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

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.

posted on 2009-11-04 10:05  jxgxy  阅读(682)  评论(0编辑  收藏  举报

导航