mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 07:31:20 +02:00
34 lines
461 B
ObjectPascal
34 lines
461 B
ObjectPascal
program tanonfunc17;
|
|
|
|
{$mode objfpc}
|
|
{$modeswitch anonymousfunctions}
|
|
{$modeswitch functionreferences}
|
|
|
|
{ test maintaining state between calls }
|
|
|
|
type
|
|
TIntFunc = reference to function: Integer;
|
|
|
|
function Foo: TIntFunc;
|
|
var
|
|
i: Integer;
|
|
begin
|
|
Result := function: Integer
|
|
begin
|
|
Result := i;
|
|
Inc(i);
|
|
end;
|
|
i := 100;
|
|
end;
|
|
|
|
var
|
|
F: TIntFunc;
|
|
i: Integer;
|
|
begin
|
|
F := Foo();
|
|
for i := 0 to 9 do
|
|
if F() <> (i + 100) then
|
|
halt(i);
|
|
end.
|
|
|