Fastscript Call Delphi Method and Delphi Call Fastscript method

Source: Internet
Author: User

Fastscript calls the Delphi process:
1. Create an event-handling method first: Tfscallmethodevent
2. Then call the Tfsscript.addmethod method, the first parameter is the syntax of the Delphi method, and the second parameter is a handle to the tfscallmethodevent link. As in Delphi there is a process for delphifunc, ...
Procedure Tform1.delphifunc (s:string; i:integer); Begin
ShowMessage (S + ', ' + inttostr (i)); End
{Tfscallmethodevent}
function Tform1.callmethod (instance:tobject; Classtype:tclass; Const methodname:string;
var params:variant): Variant; Begin
If MethodName = ' delphifunc ' then//Note the method names are all uppercase comparisons.  Delphifunc (Params[0], params[1]); End
Procedure Tform1.button1click (Sender:tobject); Begin
{Clear All items}

Fsscript1.clear;

{Script Text}

Fsscript1.lines: = Memo1.lines;
{Frglobalunit contains standard types and functions}

Fsscript1.parent: = Fsglobalunit;
{Make Delphifunc procedure visible to a script}

Fsscript1.addmethod (' procedure delphifunc (s:string; i:integer) ', Callmethod);
{Compile the script}

If Fsscript1.compile Then

Fsscript1.execute Else

{Execute if compilation was succesfull}

ShowMessage (FSSCRIPT1.ERRORMSG);

{Show an error message}

End

Delphi calls Fastscript Script

For example, if there is a process in the dynamic script that has a ' scriptfunc ', you need to write the following in the Delphi code:
Fsscript1.clear; {Script Text}
Fsscript1.lines: = Memo1.lines;
{Frglobalunit contains standard types and functions} fsscript1.parent: = Fsglobalunit;
{Make Delphifunc procedure visible to a script}
{Compile the script} if Fsscript1.compile then
{Call script function with one string parameter and one integer param} fsscript1.callfunction (' Scriptfunc ', Vararray of ([' Call Scriptfunc ', 1])) Else showmessage (fsscript1.errormsg); {Show an error message} end;
For example, the dynamic script content is as follows:
Procedure Scriptfunc (msg:string; Num:integer); Begin
ShowMessage (' 1st param: ' + Msg + ' 2nd param: ' + inttostr (Num)); End
Begin
Delphifunc (' Call Delphifunc ', 1); End.

Fastscript calls the Delphi method and Delphi calls the Fastscript method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.