[fpc-devel] Delphi anonymous methods

waldo kitty wkitty42 at windstream.net
Tue Mar 5 17:17:52 CET 2013


On 3/4/2013 15:33, Howard Page-Clark wrote:
> On 04/03/13 6:34, waldo kitty wrote:
>
>> 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 :(
>
> You can simulate this in FPC as well as TP by using a local typed constant. e.g.
>
> function GetValue: integer;
> const value: integer = 0;
> begin
> Inc(value);
> Result:= value;
> end;
>
> Successive calls to GetValue() will return 1, 2, 3 etc.

yes, that is exactly what i was thinking of... i just could not find any sample 
code in my library... as noted, i have used it and it sounds similar to what the 
OP is looking to do... one thing i used to use it for was counting the number of 
time that a routine was called during the course of execution... other times i 
used it were in relation to recursion IIRC...

NOTE: i've never done this with strings but i would guess it would work, too...



More information about the fpc-devel mailing list