blob: 8fabc16abce2da6b7c5a3c5a0c50b2fe58c36ae6 (
plain)
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
|
program test_collection;
{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
{$apptype console}
uses Classes;
type
titem = class(TCollectionItem)
public
procedure do_something;
end;
tcoll = class(TCollection)
public
procedure Update(Item: TCollectionItem); override;
end;
var
c: tcoll;
item: titem;
i: Integer;
update_counter: Integer;
procedure titem.do_something;
begin
Changed(False);
end;
procedure tcoll.Update(Item: TCollectionItem);
begin
Inc(update_counter);
inherited;
end;
begin
c := tcoll.Create(titem);
item := titem(c.Add);
update_counter := 0;
c.BeginUpdate;
try
for i := 0 to 9 do
item.do_something;
finally
c.EndUpdate;
end;
writeln('updates: ', update_counter);
if update_counter<>1 then
begin
c.Free;
Halt(1);
end;
c.Free;
writeln('ok');
end.
|