您的位置:首页 > 其它

详测 Generics Collections TList (1): Add、Clear、Count、Capacity

2009-10-10 22:21 495 查看
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses Generics.Collections;

procedure TForm1.Button1Click(Sender: TObject);
var
List: TList<Cardinal>;
i: Integer;
str: string;
begin
List := TList<Cardinal>.Create();

{Add}
List.Add(22);
List.Add(33);
List.Add(11);

{Count、Capacity}
ShowMessageFmt('Count: %d; Capacity: %d', [List.Count, List.Capacity]);

str := '';
for i in List do str := str + UIntToStr(i) + sLineBreak;
ShowMessage(str);

{Clear}
List.Clear;
ShowMessageFmt('Count: %d; Capacity: %d', [List.Count, List.Capacity]);

List.Free;
end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: