(advanced) Read Basic4ppc thread parameters

Erel

Administrator
Staff member
Licensed User
As of version 6.80 Basic4ppc stores several values in the main thread slots.
This allows external libraries to read these parameters and act accordingly.
The C# code is:
B4X:
(double)Thread.GetData(Thread.GetNamedDataSlot("fixX"))
(double)Thread.GetData(Thread.GetNamedDataSlot("fixY"))
(double)Thread.GetData(Thread.GetNamedDataSlot("scaleX"))
(double)Thread.GetData(Thread.GetNamedDataSlot("scaleY"))
(bool)Thread.GetData(Thread.GetNamedDataSlot("cPPC"))
(bool)Thread.GetData(Thread.GetNamedDataSlot("optimized"))
scaleX / scaleY - have the same value as Basic4ppc keywords ScreenScaleX / ScreenScaleY.
fixX / fixY - used in AutoScale compilation. See this thread for more information: http://www.basic4ppc.com/forum/beta-versions/4207-autoscale-compilation-mode-external-libraries.html
cPPC - same as Basic4ppc cPPC (true when running on the device and false on the desktop).
optimized - True for optimized compiled applications and false otherwise.

It is also possible to read these values from Basic4ppc with the door library.
Basic4ppc code:
B4X:
Sub ReadValueFromThread (property)
    AddObject("obj1", "Object")
    AddObject("obj2", "Object")
    AddObject("objArr", "ObjectArray")
    obj1.New1(True)
    obj2.New1(False)
    obj1.CreateNew("System.Threading.Thread" & obj1.System_Mscorlib)
    obj2.Value = obj1.RunMethod2("GetNamedDataSlot", property, "System.String")
    objArr.New1(1)
    objArr.SetObject(0, obj2.Value)
    ret = obj1.RunMethod4("GetData", objArr.Value)
    obj1.Dispose
    obj2.Dispose
    objArr.Dispose
    Return ret
End Sub
Note that this code requires Door library v1.2 or newer.
 

eww245

Member
Licensed User
This is Good... Thanks

I was resently wondering how to get some properties without using reflection.
Guess this is a start.

I noticed the Threading library has using DBasic.
Which would also be a way to get info from b4p.

But that's a different topic.

Thanks Again,
E
 

Erel

Administrator
Staff member
Licensed User
(super advanced) ;)
There are two additional objects in this list:
Thread.GetData(Thread.GetNamedDataSlot("b4p"));
Thread.GetData(Thread.GetNamedDataSlot("CRunner"));
b4p - returns for optimized compiled applications a reference for the main object.
CRunner - returns for IDE or nonoptimized compiled applications a reference to the main IDE.
 

agraham

Expert
Licensed User
<even more super advanced>) :cool:
I noticed the Threading library has using DBasic.
The reason for this is to reference the delegate types declared in Basic4ppc at compile time. The delegates types are required to call optimised compiled Subs from a library. This is needed for Threading to run on the device as in the Compact Framework Reflection does not let you instatiate delegate types at runtime because it lacks the CreateDelegate method.

A compile time reference to Dbasic is normally not needed to use Reflection on the Crunner or b4p objects on the device (or desktop)as the Compact Framework fully supports Reflection on properties, fields and methods (as far as I've needed it so far!). My Debug library relies entirely on Reflection to work its' magic.
</even more super advanced>
 
Last edited:
Top