blob: ba287190191fa7e02f39836a4abef3088ee84da6 (
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
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
|
{ Source provided for Free Pascal Bug Report 4015 }
{ Submitted by "Radoslaw Stachowiak" on 2005-05-25 }
{ e-mail: zenek_tm@tenbit.pl }
unit tw4015;
{$mode objfpc}
{$inline on}
{$H+}
interface
type
TComponent = class;
{ TComponentContainer }
TComponentContainer = class
private
acount: integer;
components: array of TComponent;
function fGet(ind: integer): TComponent; inline;
public
constructor Create;
destructor Destroy; override;
property Component[ind: integer]: TComponent read fGet; default;
property Count: integer read acount;
end;
{ TComponent }
TComponent = class
protected
achildren: TComponentContainer;
public
constructor Create(const parent: TComponent);
destructor Destroy; override;
end;
implementation
{ TComponentContainer }
function TComponentContainer.fGet(ind: integer): TComponent; inline;
begin
if (ind>=acount) or (ind<0) then
result := nil
else
result := components[ind];
end;
constructor TComponentContainer.Create;
begin
inherited Create;
acount:=0;
SetLength(components, 10);
end;
destructor TComponentContainer.Destroy;
begin
inherited Destroy;
end;
{ TComponent }
constructor TComponent.Create(const parent: TComponent);
begin
inherited Create;
achildren := TComponentContainer.Create;
end;
destructor TComponent.Destroy;
var
i: integer;
begin
for i:=0 to achildren.Count-1 do
begin
achildren[i].Free(); //Internal Error 200108231
{if above line is changed to (var c: TComponent):
c := achildren[i]; //Internal Error 200108231
c.Free();
}
end;
achildren.Free;
inherited Destroy;
end;
end.
|