详测 Generics Collections TList (7): Items、Contains


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<string>;

  b: Boolean;

begin

  List := TList<string>.Create();

  List.AddRange(['AA', 'BB', 'CC']);



  ShowMessageFmt('%s : %s', [List[1], List.Items[1]]); {BB : BB}



  b := List.Contains('BB');

  ShowMessage(BoolToStr(b, True)); {True}



  b := List.Contains('DD');

  ShowMessage(BoolToStr(b, True)); {False}



  List.Free;

end;



end.


 
   

你可能感兴趣的:(Collections)