-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtcapturedinlineinterface2.pp
More file actions
109 lines (98 loc) · 1.89 KB
/
Copy pathtcapturedinlineinterface2.pp
File metadata and controls
109 lines (98 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
program tcapturedinlineinterface2;
{$ifdef FPC}
{$mode delphiunicode}
{$modeswitch anonymousfunctions}
{$modeswitch functionreferences}
{$modeswitch inlinevars}
{$endif}
type
ITracked = interface
['{1B4D628F-DC89-46FB-8F4B-E5364633F35B}']
end;
TTracked = class(TInterfacedObject, ITracked)
public
class var Alive: LongInt;
constructor Create;
destructor Destroy; override;
end;
TAction = reference to procedure;
constructor TTracked.Create;
begin
inherited;
Inc(Alive);
end;
destructor TTracked.Destroy;
begin
Dec(Alive);
inherited;
end;
procedure RunSynchronous;
begin
for var I:=1 to 3 do begin
var Token: ITracked:=TTracked.Create;
var Action: TAction:=procedure
begin
If Token=nil then
Halt(1);
end;
Action();
If TTracked.Alive<>1 then
Halt(2);
end;
end;
procedure RunTwoCaptured;
begin
for var I:=1 to 3 do begin
var Left: ITracked:=TTracked.Create;
var Right: ITracked:=TTracked.Create;
var Action: TAction:=procedure
begin
If (Left=nil) or (Right=nil) then
Halt(7);
end;
Action();
If TTracked.Alive<>2 then
Halt(8);
end;
end;
procedure RunUninitialized;
begin
var Token: ITracked;
Token:=TTracked.Create;
var Action: TAction:=procedure
begin
If Token=nil then
Halt(9);
end;
Action();
end;
function MakeLast: TAction;
begin
for var I:=1 to 3 do begin
var Token: ITracked:=TTracked.Create;
Result:=procedure
begin
If Token=nil then
Halt(3);
end;
end;
end;
var
Action: TAction;
begin
RunSynchronous;
If TTracked.Alive<>0 then
Halt(4);
RunTwoCaptured;
If TTracked.Alive<>0 then
Halt(10);
RunUninitialized;
If TTracked.Alive<>0 then
Halt(11);
Action:=MakeLast();
If TTracked.Alive<>1 then
Halt(5);
Action:=nil;
If TTracked.Alive<>0 then
Halt(6);
end.