详测 Generics Collections TList (4): AddRange、InsertRange、DeleteRange


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,ListTmp: TList<Byte>;

  i: Byte;

  str: string;

begin

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

  List.AddRange([11,22,33]);



  str := '';

  for i in List do str := str + IntToStr(i) + ' '; {11 22 33 }

  ShowMessage(str);



  ListTmp := TList<Byte>.Create();

  ListTmp.AddRange([44,55]);



  List.AddRange(ListTmp);

  str := '';

  for i in List do str := str + IntToStr(i) + ' '; {11 22 33 44 55 }

  ShowMessage(str);



  List.InsertRange(1, ListTmp);

  str := '';

  for i in List do str := str + IntToStr(i) + ' '; {11 44 55 22 33 44 55 }

  ShowMessage(str);



  List.DeleteRange(1, 5);

  str := '';

  for i in List do str := str + IntToStr(i) + ' '; {11 55 }

  ShowMessage(str);

  

  ListTmp.Free;

  List.Free;

end;



end.


 
   

你可能感兴趣的:(Collections)