[fpc-pascal] Re: Delphi's anonymous functions in Free Pascal
Marco van de Voort
marcov at stack.nl
Sat Nov 5 20:08:10 CET 2011
In our previous episode, Bernd said:
> > Equivalent solution with anon functions:
> >
> > targethread.queue(
> > ? procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
> > ? ? ? ? ? ? ?begin
> > ? ? ? ? ? ? ? ?targetobject.destinationprocedure(a,b,c);
> > ? ? ? ? ? ? ?end;
>
> shouldn't this be
>
> targethread.queue(
> procedure
> begin
> targetobject.destinationprocedure(a,b,c);
> end;
>
> without any parameters since all these variables are captured from the
> current scope into the closure? The other thread should not need to
> know anything about them to call it.
Afaik you are right. Delphi also allowed the other form, but I thought the
syntax would force immediately evaluation of the parameters (and thus only
the parameters be stored in case any of a ,b or c are expressions, not all
parts of the expressions).
But indeed then the other side also has to call it with parameters, and in
this example that defeats the purpose.
More information about the fpc-pascal
mailing list