unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,generics.Collections, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TStud=class(TObject)
public
studname:String;
age :integer;
function toString(): String;
private
end;
var
Form1: TForm1;
list:TList<String>;
studList:TList<TStud>;
implementation
{$R *.dfm}
{*
The Tiburon Generics.Collections unit includes: TList, TQueue, TStack, TDictionary, TObjectList, TObjectQueue, TObjectStack, and TObjectDictionary.
*}
function TStud.toString;
begin
toString:= studname+ ' - '+ inttostr(age);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
list.Free;
studList.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
str:string;
i:integer;
j:integer;
stud:TStud;
begin
list:=TList<String>.Create;
studList:=TList<TStud>.Create;
stud.Create ;
stud.studname:='小裴';
stud.age:=26;
studList.Add(stud);
list.Add('A');
list.Add('B');
list.Add('C');
for i := 0 to List.Count - 1 do
str:=str+'-'+list.Items[i];
edit1.Text:=str;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
str:string;
begin
try
list.Delete(0);
except
showmessage('超出范围');
end;
for i := 0 to List.Count - 1 do
str:=str+'-'+list.Items[i];
edit1.Text:=str;
end;
end.
posted on 2008-11-12 13:39
有猫相伴的日子 阅读(411)
评论(0) 编辑 收藏 所属分类:
delphi