Skip to content

Instantly share code, notes, and snippets.

@kevroletin
Created March 2, 2013 13:58
Show Gist options
  • Save kevroletin/5071119 to your computer and use it in GitHub Desktop.
Save kevroletin/5071119 to your computer and use it in GitHub Desktop.
program capture_by_value;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
TProc = reference to procedure;
TFunct = reference to function: TProc;
var
procArr: array[1..5] of TProc;
procedure HumanFactory;
function Call(funct: TFunct): TProc;
begin
Result := funct();
end;
var i: Integer;
begin
for i := 1 to 5 do
begin
procArr[i] := Call(
function : TProc
var inner: Integer;
begin
inner := i;
Result := procedure begin Writeln(inner); end;
end
);
end;
end;
var i: Integer;
begin
HumanFactory();
for i := 1 to 5 do begin
procArr[i]();
end;
Readln;
end.
@kevroletin
Copy link
Author

Output
1
2
3
4
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment