Hi,
Is it possible to pass a parameter of procedural type from Pascal Script to the procedure of Delphi code? I thought that yes but…
There is the Pascal Script code:
program test;
procedure WindowSpecificAction(const wnd: HWND);
begin
// some code here...
end;
begin
ForEachWindow(@WindowSpecificAction);
end.
The procedure ForEachWindow defined in my Delphi code:
type
TWindowSpecificAction = procedure(const wnd: HWND);
procedure ForEachWindow(Proc: TWindowSpecificAction);
var
wnd : HWND;
begin
//some code here...
Assert(@Proc <> nil); // EAssertionFailed with message 'Assertion failure...'
Proc(wnd);
end;
...
ScriptCompiler.AddTypeS('TWindowSpecificAction', 'procedure (wnd: HWND)');
ScriptCompiler.AddDelphiFunction('procedure ForEachWindow(WindowSpecificAction: TWindowSpecificAction);');
ScriptInterpreter.RegisterDelphiFunction(@ForEachWindow, 'ForEachWindow', cdRegister);
...
And when the script executed I catched the exception.
Could you please show my mistake?
Thank you for advance.
Regards.