-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpcdefer.pas
46 lines (38 loc) · 917 Bytes
/
fpcdefer.pas
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
{
CudaText: lexer_file=Pascal; tab_size=2; tab_spaces=Yes; newline=LF;
}
{$mode objfpc}
{$H+}
{$modeswitch anonymousfunctions}
{$modeswitch functionreferences}
{$modeswitch advancedrecords}
unit fpcdefer;
interface
type
tDeferProc = reference to procedure;
tDeferred = array of tDeferProc;
tDefer = record
strict private
deferred: tDeferred;
class operator finalize (var self: tDefer);
public
procedure add (const _deferred: tDeferProc);
property x: tDeferProc write add;
procedure anchor;
end;
implementation
procedure tDefer.anchor; // empty placeholder
begin
end;
class operator tDefer.finalize (var self: tDefer);
var
i: integer;
begin
for i := high(self.deferred) downto low(self.deferred) do self.deferred[i]();
end;
procedure tDefer.add (const _deferred: tDeferProc);
begin
insert(_deferred, deferred, length(deferred));
end;
begin
end.