Marco van de Voort wrote:
How does it work effectively? So something like:
procedure proc1(x:longint);
procedure proc2(x:longint);
begin end;
begin end;
type myproctype=procedure(x:longint);
procedure proc3(x:pointer);
begin myproctype(x); end;
begin proc3(@proc1); proc3(@proc2); end;
This does not work because 1) `myproctype(x)' lacks an argument to the called procedure, and 2) your "main program" does not know `proc2' which is local to `proc1'.
The following _does_ work:
program foo;
type myproctype=procedure(x:longint);
procedure proc3(x:pointer);
begin myproctype(x)(21); end;
procedure proc1(x:longint);
procedure proc2(y:longint);
begin writeln(2*x) end;
begin proc3(@proc2) end;
begin proc3(@proc1) end.
GPC uses "trampolines" to pass the pointer of the local procedure. (See `info -f jarg400 -n trampoline'.)
Peter