Dynamic load module method

Is there a way to load a method of a module? I found a question from Björn Eiríksson in the year 2016:
Encodings_DOSThai = (REALobject (*)()) REALLoadGlobalMethod(“Encodings.DOSThai() as TextEncoding”);
This is some time ago. Is there a workaround for it?

I don’t think you would need to load that one. The encodings in the SDK are integer constant, so chances are if you messagebox out the code of the DOSThai in Xojo then you find the integer constant.

Ah I did not fully read the example was mine !! And I guess I did solve it as described above.

I think since then some methods in namespace could be loaded. Think William did something not long ago for that ??

you can hard code the value. Should be 1053 for DOS Thai.

And than pass that number for REALBuildStringWithEncoding as encoding.

I’m sorry, the code I wrote was just the example from Björn, I didn’t need it. Yesterday I tried
REALLoadFrameworkMethod("System.Ticks() As Integer") and get nil returned. If I write REALLoadFrameworkMethod("Ticks() As Integer") , I get a valid function pointer. I don’t know if this is the “outdated” Xojo function, and if it’s supported in the future versions of Xojo. As I understand, I cannot get any method from a module?? Or I’m wrong?

Its one of those strange cases, System is not a module, it just pretends to be module.

The function returns the system object. (Pointed out by Xojo them self at some point in time)

I dont know of other way than sending getSystemObject to the Resolver to get the system object.

Thank you for your response Björn. If I use the function “getSystemObject”, I got the object back, but I’m not been able to access any of the system methods. So REALLoadFrameworkMethod("System.Ticks() As Integer") is the only solution that is working. If I know the name and method of a module, for example from another plug-in, I never get the chance to access the function, right? Or does this only happen with the Xojo modules. I’m sorry for all these questions, but the SDK documentation is more than poor.

Use REALLoadObjectMethod once you have the object, its after all Instance method and not global method.

REALLoadObjectMethod is not working here. I got the system object, let’s say sysObject, with the getSystemObject funtion by the resolver. However if I call REALLoadObjectMethod(sysObject, “Ticks() As Integer”) will return nil too.

That’s actually odd that that would work. and that

is odd that it would not work.

Since “System() as _SystemClass” can be regarded a singleton, perhaps Ticks is a shared method you can assess with:

void *REALLoadSharedMethod(REALclassRef classRef, const char *prototype);

and that could do the trick?

Hello Alfred,
thank you for your feedback. I can get the REALclassRef from the “_SystemClass”, but it has no prototype “Ticks() As Interger” and return nil as function pointer too.

Try loading it with:

REALLoadSharedMethod

Which also takes the class ref

And if nothing works then just use the old school one which works:

RBInteger Ticks()
{
static Ticks_Proc Ticks_fp = 0;

if(!Ticks_fp)
    Ticks_fp = (Ticks_Proc)REALLoadFrameworkMethod("Ticks() as Integer");

return Ticks_fp();

}

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.