[fpc-devel] Delphi anonymous methods

waldo kitty wkitty42 at windstream.net
Mon Mar 4 19:34:31 CET 2013


> It is as I thought about closures before. But this is useless without capturing
> of variables by value. During creation of anonymous method you *can not bind any
> values* to it. Anonymous method have only references to captured variables.
> Pascal don't allows to create static variables inside function like in c-like
> languages. So you also not able to create unique static variable which available
> only to one instance of same anonymous method. Even if implementation will
> create many separate objects for one anonymous function then all instances will
> be equivalent. Because all instances will refer to same data.

i'm trying to understand what you mean by

 > Pascal don't allows to create static variables inside function like in c-like
 > languages.

i've done something that i think is what you speak of but it was in Borland's 
Turbo Pascal... at least TP6... i don't remember how we did it though and can't 
find any sample code in my library :(

what happened is that the value did not get cleared between invocations of the 
routine and subsequent executions could use the value already stored... this 
breaks, of course, if the memory area for the routine is cleared first...




More information about the fpc-devel mailing list