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