Der Vollständigkeit halber der Code, den ich zum Testen benutze:
Delphi-Quellcode:
type
TTest = class
private
FID: Integer;
protected
property ID: Integer read FID;
public
constructor Create(AID: Integer);
destructor Destroy; override;
end;
constructor TTest.Create(AID: Integer);
begin
inherited Create;
FID := AID;
ShowMessage(Format('create %d', [Id]));
end;
destructor TTest.Destroy;
begin
ShowMessage(Format('destroy %d', [Id]));
inherited;
end;
procedure Test;
var
L: TObjectList;
begin
L := TObjectList.Create();
ShowMessage('A');
L.Add(TTest.Create(1));
ShowMessage('B');
L[0] := TTest.Create(2);
ShowMessage('C');
L.Free;
ShowMessage('D');
end;
Die Meldungen sind dann:
A
create 1
B
create 2
destroy 1
C
destroy 2
D