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-10-10 22:21  万一  阅读(2895)  评论(2编辑  收藏  举报