Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Dynamically connecting the application host procedure to the script

Hello.

Please tell me how you can connect the function from the host application to the script "on the fly", that is, during the execution of the program?

I tried to do this, but nothing worked.

getSumLocal := @GetSUM;

LMDScriptControl1.AddObject('getSumLocal', TLMDEventWrapper.ToVar(LMDScriptControl1, 'getSumLocal'));
LMDScriptControl1.Active := True;
LMDScriptControl1.RunProc('Button1Click', [0]);



I attach an example application.

Thank you.
rar
rar
Test1.rar
5K
jpg
jpg
07072021_155428.jpg
21K
Tagged:

Comments

  • 4 Comments sorted by Votes Date Added
  • There no way. 

    1) Everything you want to add into the script should be wrapped by the Import Wizard.
    2) LMD ScriptPack does not support pointer types, including pointers to procedures. Global procedures are treated as members of a unit (analogous to class methods).

    So, you can do either:

    - Declare your procedure as a global procedure in some unit, and create wrappers for the unit using Import Wizard. Then, use ScriptControl.AddUnit.
    - Declare class with a method instead of global procedure. Import the unit using Import Wizard. Then use something like this: 

    obj := TMyObject.Create;
    vr  := TMyObject_sw.ToVar(obj);

    MyScriptControl.AddObject('MyUtils', vr, True);

    Note that the last APublishMembers parameter of the AddObject method is set True, which forces the engine to make all object's methods globally accessible in the script.



  • edited July 8 Posts: 7Vote Up0Vote Down
    I will try your recommendations.
    Thank you very much for your reply.

  • Hello.

    On your advice, I created a class to implement the necessary functions. I made a wrapper for him with the help of a wizard.

    But I get an error when compiling. Tell me what to do?
    jpg
    jpg
    08072021_152352.jpg
    67K
  • All destructors in Delphi should be virtual. So, add the "override" directive after it:

    destructor Destroy; override;
Sign In or Register to comment.