Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,19 +1,27 @@
program Project1;
type
TFuncIntResult = reference to function : integer;
TFuncIntResult = reference to function: Integer;
// use function that returns anonymous method to avoid capturing the loop variable
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs : array [0..9] of TFuncIntResult;
i : integer;
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
// Create 10 anonymous functions
// create 10 anonymous functions
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := function() : integer begin Result := i*i; end;
Funcs[i] := CreateFunc(i);
// call all 10 functions
for i := Low(Funcs) to High(Funcs) do
writeln( Funcs[i]() );
Writeln(Funcs[i]());
end.