刚刚发到另外一个地方了,我写个例子给你算了,SetLength会存在实例不能释放的问题,因为你存的是类的实例,不是普通变量,
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TPerson = class
Name : string;
Sex : Boolean;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FPersonList : TList;
public
{ Public declarations }
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
I : Integer;
Person : TPerson;
begin
for I := 0 to 99 do begin
Person := TPerson.Create;
Person.Name := IntTostr(i);
FPersonList.Add(Person);
end;
end;
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
FPersonList := TList.Create;
end;
destructor TForm1.Destroy;
var
I : Integer;
begin
for I:= 0 to FPersonList.Count -1 do
TPerson(FPersonList.Items).Free;
FPersonList.Free;
inherited;
end;
end.