type
TSmt = record
SName: string[16];
Feeder: Integer;
Dushu: Real;
end;
Psmt = ^TSmt;
var
List: TList; //List:Tlist<Psmt>; 泛型指针Tlist uses Generics.Collections;
procedure TForm2.Button1Click(Sender: TObject);
var
buf: Psmt;
i: Integer;
begin
if not Assigned(list) then
begin
List := TList.Create; //List:=Tlist<Psmt>.create;
for i := 0 to 10 do
begin
New(buf); // 这里用指针比直接用Tsmt方便,不用申明多个Tsmt变量
buf.SName := '第' + Inttostr(i) + '个链表!';
List.Add(buf);
ShowMessage((Psmt(List.Items[i])^).SName);
end;
end
else
ShowMessage('无须重复');
end;
procedure TForm2.Button2Click(Sender: TObject);
var
i: Integer;
begin
if (Assigned(List)) and (List.Count > 0) then
begin
for i := List.Count - 1 downto 0 do
begin
if Assigned(List.Items[i]) then
begin
ShowMessage((Psmt(List.Items[i])^).SName);
Dispose(List.Items[i]);
List.Delete(i);
end;
end;
FreeAndNil(List);
end
else
ShowMessage('链表为空或未创建对象实例');
end;