至少2种方法:
1、
procedure TForm1.PSScriptCompile(Sender: TPSScript);
begin
Sender.AddFunction(@MyWriteln, 'procedure Writeln(s: string);');
Sender.AddFunction(@MyWrite, 'procedure Write(s: string);');
Sender.AddFunction(@MyReadln, 'function Readln(question: string): string;');
Sender.AddFunction(@ImportTest, 'function ImportTest(S1: string; s2: Longint; s3: Byte; s4: word; var s5: string): string;');
Sender.AddFunction(@PutDataToPS, 'function PutDataToPS:TStrings;');
Sender.AddFunction(@GetDataFromPS, 'procedure GetDataFromPS(d:TStrings);');
//就是这样:解释时,告诉解释器那些控件是什么类型的
Sender.AddRegisteredVariable('Application', 'TApplication');
Sender.AddRegisteredVariable('Self', 'TForm');
Sender.AddRegisteredVariable('Memo1', 'TMemo');
Sender.AddRegisteredVariable('Memo2', 'TMemo');
end;
procedure TForm1.PSScriptExecute(Sender: TPSScript);
begin
//运行时,告诉运行者:脚本里的那些对象 实际对应的是 delphi程序里的那些控件对象
PSScript.SetVarToInstance('APPLICATION', Application);
PSScript.SetVarToInstance('SELF', Self);
PSScript.SetVarToInstance('MEMO1', Memo1);
PSScript.SetVarToInstance('MEMO2', Memo2);
end;
脚本的写法:
writeln(memo1.lines.text);
memo2.lines.text:=memo2.lines.text+'-------------'+#13#10+memo1.lines.text;
memo2.color:=cllime;
writeln(application.title);
application.title:='<<<<'+application.title+'>>>>';
writeln(application.title);
2、
在delphi程序里预先写好,按名访问delphi程序里的控件的方法,
然后,让脚本去用--这样,脚本程序访问起来略有点别扭