Problem with parameter of procedural type

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.

PascalScript only supports “of object” type method pointers, change it to that and it should work.

Thank you @ck!

I’ve changes signature of proc type:

type
  TWindowSpecificAction = procedure(const wnd: HWND) of object;

and

ScriptCompiler.AddTypeS('TWindowSpecificAction', 'procedure (wnd: HWND) of object;');

And now it’s works for me!
But is it OK? I’m not used objects in this code…

Yeah that’s fine. PascalScript puts stuff in the “self” to direct the call to the right place.