Thread and FormEx libraries with 6.42

agraham

Expert
Licensed User
Longtime User
To use the Threading library with the latest version you will need to change the name of the thread Sub by prefixing the Sub name with "_ModuleName_"
B4X:
Thread.Start("_Main_ThreadCode")

To use Threading with a FormEx you will also need to change the name of the Thread.
B4X:
FormEx1.EnableThreading("_Main_Thread1", B4PObject(1))
...
Thread1.Start("_Main_ThreadCode")
I am pondering whether to change the code of both libraries so that you can do
B4X:
Thread1.Start("Main.ThreadCode")
Any opinions?

EDIT:- Having typoed the title of this threead I can find no way of editing it! Is it possible?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why two underscores?
The parser now adds one and the optimized compiler adds another one (the compiler wasn't changed).

I agree, it should be backwards compatible. You can use B4P method:
B4X:
ThreadSub = "_" + Other.FixRuntimeControlName(ThreadSub,"main");
The code for FixRuntimeControl is:
B4X:
public static string FixRuntimeControlName(string controlName, string moduleName)
        {
            controlName = controlName.ToLower(b4p.cul);
            if (controlName.IndexOf(".") > -1)
                return "_" + controlName.Replace(".", "_");
            else
                return "_" + moduleName + "_" + controlName;
        }
 

agraham

Expert
Licensed User
Longtime User
Why moduleName for pre-6.42? I'm using this which seems to work for both 6.30 and 6.42
B4X:
private String b4pname(String name)
{
    if (name.IndexOf('.') >= 0)
    {
        return "__" + name.ToLower(cul).Replace(".", "_");
    }
    return "_" + name.ToLower(cul);
 }

EDIT :- I've looked at Other.cs and seen what that code is meant to do (add the default module name if none specified), but it is not applicable here as pre 6.42 only the Sub name is in htSubs with no qualification.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I meant that it will be compatible with existing code running under the new version.
For "compatible" I meant that the library would optimise compile and run with earlier versions of B4ppc. It would seem that we can't have both sorts of compatibility :( or maybe we can if I look for two leading underscores in htSubs - I'll think about it :confused:
 

agraham

Expert
Licensed User
Longtime User
Compatibility all round! - dead easy :)
B4X:
         IEnumerator ienum = htSubs.Keys.GetEnumerator();
         enum.MoveNext();
         String str = (String)ienum.Current;
         if (str.Substring(0, 2) == "__")
             modules = true;
        ....
        private String b4pname(String name)
        {
            if (name.IndexOf('.') >= 0)
            {
                // >6.42  & module.name
                return "__" + name.ToLower(cul).Replace(".", "_");
            }
            if (modules)
            {
                // >6.42  & name
                return "__" + "main_" + name.ToLower(cul);
            }
            // 6.30 or earlier
            return "_" + name.ToLower(cul);
        }
 
Top