我可以注册这样的自定义函数:
procedure TForm1.PSScript1ExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
se.RegisterDelphiFunction(@MWrites, 'Writes', cdRegister);
end;
和像这样的自定义类:
procedure TForm1.PSScript1ExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
var CustomClass: TPSRuntimeClass;
begin
CustomClass := x.Add(TPerson);
CustomClass.RegisterMethod(@TPerson.setAge, 'setAge');
end;
type TCallback = procedure;
但是如何将TCallback添加到PascalScript中?
type
TCallback = procedure;
TPerson = class(TObject)
procedure setAge(AValue: TCallback);
end;
procedure TForm1.PSScript1Compile(Sender: TPSScript);
var CustomClass: TPSCompileTimeClass;
begin
CustomClass := Sender.Comp.AddClass(Sender.Comp.FindClass('TObject'), TPerson);
Sender.Comp.AddTypeS('TCallback', 'procedure');
Customclass.RegisterMethod('procedure setAge(AValue: TCallback)');
end;