Anonymous user
Closures/Value capture: Difference between revisions
Fixed code to not use wrong variable capturing that got hidden by looping again using that variable.
(Fixed code to not use wrong variable capturing that got hidden by looping again using that variable.) |
|||
Line 399:
type
TFuncIntResult = reference to function
// use function that returns anonymous method to avoid capturing the loop variable
var▼
function CreateFunc(i:
begin
i : integer;▼
Result :=
function: Integer
begin
Result := i * i;
end;
end;
▲var
Funcs: array[0..9] of TFuncIntResult;
begin
//
for i := Low(Funcs) to High(Funcs) do
Funcs[i] :=
// call all 10 functions
for i := Low(Funcs) to High(Funcs) do
end.</lang>
{{out}}
|