[fpc-pascal] Re: Delphi's anonymous functions in Free Pascal
Michael Van Canneyt
michael at freepascal.org
Sat Nov 5 22:46:12 CET 2011
On Sat, 5 Nov 2011, Bernd wrote:
> 2011/10/25 <michael.vancanneyt at wisa.be>:
>
>>> targethread.queue(
>>> procedure(targetobject:ttargetobject;a:integer;b:someobject;c:string)
>>> begin
>>> targetobject.destinationprocedure(a,b,c);
>>> end;
>>>
>>> Note how common this looks compared to the original.
>>
>> One point is that you could do the above with a local (and named) procedure
>> as well, and still have all the context. At the very least you would not be
>> raping pascal's readability by putting a
>> complete procedure declaration inside a code block.
>
> How would you preserve the context without finding some place
> somewhere (on the heap) to store the current values of a, b, and c?
>
Procedure SomeOuter;
Var
d,e,f : SomeType;
Procedure SomeInner(targetobject:ttargetobject;a:integer;b:someobject;c:string)
begin
targetobject.destinationprocedure(a,b,c);
end;
begin
Targethread.queue(@SomeInner(aobject,d,e,f));
end;
No difference with 'closure', except more readable.
Michael.
More information about the fpc-pascal
mailing list