十二、详测 Generics Collections TList (3): Insert、Delete、Remove、Extract

unit Unit1;

interface

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

type
  TForm1 
= class(TForm)
    Button1: TButton;
    
procedure Button1Click(Sender: TObject);
  
private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  Generics.Collections;

procedure TForm1.Button1Click(Sender: TObject);
var
  List: TList
<Integer>;
  i: Integer;
  str: 
string;
begin
  List :
= TList<Integer>.Create;
  list.Add(
111);
  list.Add(
222);
  list.Add(
333);
  list.Add(
444);
  list.Add(
555);
  List.Insert(
0,888); //Insert
  List.Insert(
2,999);
  str :
= '';
  
for i in List do str := str + UIntToStr(i) + ' ';
  ShowMessage(str);

  List.Delete(
0);  //Delete
  List.Delete(List.count 
- 1);
  str :
= '';
  
for i in List do str := str + UIntToStr(i) + ' ';
  ShowMessage(str);
  List.Remove(
333);    //Remove
  str :
= '';
  
for i in List do str := str + UIntToStr(i) + ' ';
  ShowMessage(str);
  List.Extract(
222);   //Extract
  str :
= '';
  
for i in List do str := str + UIntToStr(i) + ' ';
  ShowMessage(str);
  List.Free;
end;

end.

posted on 2009-11-04 13:15  jxgxy  阅读(506)  评论(0编辑  收藏  举报

导航