This forum is temporaily read-only. All existing discussions remain available for reference. For new questions, bug reports or support requests, please contact us at mail@lmdsupport.com.

Dynamically connecting the application host procedure to the script

edited July 2021 in LMD IDE-Tools
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.

Comments

  • edited July 2021
    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 2021
    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?
  • All destructors in Delphi should be virtual. So, add the "override" directive after it:

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