开发环境Delphi7
一个小测试,记录下
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Button1: TButton; 12 Button2: TButton; 13 Button3: TButton; 14 Button4: TButton; 15 Button5: TButton; 16 Button6: TButton; 17 procedure FormCreate(Sender: TObject); 18 procedure Button1Click(Sender: TObject); 19 procedure Button5Click(Sender: TObject); 20 procedure Button2Click(Sender: TObject); 21 procedure Button3Click(Sender: TObject); 22 procedure Button4Click(Sender: TObject); 23 procedure Button6Click(Sender: TObject); 24 private 25 { Private declarations } 26 public 27 Flist01:TStrings; 28 Flist02:TStrings; 29 Flist_01:TStrings; 30 procedure setss(s:string); 31 { Public declarations } 32 end; 33 TMyP=procedure(ss:string) of object; 34 var 35 Form1: TForm1; 36 37 implementation 38 uses 39 DB ; 40 {$R *.dfm} 41 42 procedure TForm1.FormCreate(Sender: TObject); 43 begin 44 Flist01:=TStringList.Create; 45 Flist02:=TStringList.Create; 46 Flist01.Delimiter:=';'; 47 Flist01.DelimitedText :='a=a00;b=b11'; 48 //Flist01.Text:='a=000;b=111'; 49 Flist02.Delimiter:=';'; 50 Flist02.DelimitedText :='A=A00;B=B11'; 51 Flist_01:=TStringList.Create; 52 53 54 end; 55 56 procedure TForm1.Button1Click(Sender: TObject); 57 var 58 list:TList; 59 M:TMyP; 60 begin 61 Flist_01.AddObject('Flist01',Flist01); 62 Flist_01.AddObject('Flist02',Flist02); 63 M:=setss; 64 Flist_01.AddObject('setss',@M); 65 end; 66 67 procedure TForm1.Button5Click(Sender: TObject); 68 begin 69 ShowMessage(Flist01.Values['a']+';'+Flist02.Values['A']); 70 end; 71 72 procedure TForm1.Button2Click(Sender: TObject); 73 begin 74 if Flist_01=nil then 75 Exit; 76 //Flist_01释放掉,不会把 Flist_01添加的对象释放掉 //Flist_01释放后 点击Button5还是可以访问Flist01的 77 Flist_01.Free ; 78 Flist_01:=nil; 79 end; 80 81 procedure TForm1.Button3Click(Sender: TObject); 82 begin 83 if Flist_01=nil then 84 Flist_01:=TStringList.Create; 85 end; 86 87 procedure TForm1.Button4Click(Sender: TObject); 88 begin 89 if Flist_01=nil then 90 Exit; 91 if Flist_01.IndexOf('flist0')>-1 then 92 begin 93 ShowMessage('00'); 94 end; 95 ShowMessage((Flist_01.Objects[Flist_01.IndexOf('flist01')] as TStrings).Values['a']); 96 97 //ShowMessage((Flist_01.Objects[Flist_01.IndexOf('Flist01')] as TStrings).Values['a']); 98 ShowMessage((Flist_01.Objects[Flist_01.IndexOf('Flist02')] as TStrings).Values['a']); 99 end; 100 101 procedure TForm1.setss(s: string); 102 begin 103 ShowMessage(s); 104 end; 105 106 procedure TForm1.Button6Click(Sender: TObject); 107 var 108 ss:TMyP; 109 begin 110 @ss:=Flist_01.Objects[Flist_01.IndexOf('setss')]; 111 ss('00'); 112 //(Flist_01.Objects[Flist_01.IndexOf('setss')]('000'); 113 end; 114 115 end.
1 object Form1: TForm1 2 Left = 766 3 Top = 362 4 Width = 514 5 Height = 340 6 Caption = 'Form1' 7 Color = clBtnFace 8 Font.Charset = DEFAULT_CHARSET 9 Font.Color = clWindowText 10 Font.Height = -11 11 Font.Name = 'MS Sans Serif' 12 Font.Style = [] 13 OldCreateOrder = False 14 OnCreate = FormCreate 15 PixelsPerInch = 96 16 TextHeight = 13 17 object Button1: TButton 18 Left = 24 19 Top = 16 20 Width = 137 21 Height = 25 22 Caption = 'Button1_添加到_01' 23 TabOrder = 0 24 OnClick = Button1Click 25 end 26 object Button2: TButton 27 Left = 24 28 Top = 64 29 Width = 145 30 Height = 25 31 Caption = 'Button2_释放_01' 32 TabOrder = 1 33 OnClick = Button2Click 34 end 35 object Button3: TButton 36 Left = 24 37 Top = 112 38 Width = 129 39 Height = 25 40 Caption = 'Button3_创建_01' 41 TabOrder = 2 42 OnClick = Button3Click 43 end 44 object Button4: TButton 45 Left = 16 46 Top = 184 47 Width = 185 48 Height = 25 49 Caption = 'Button4_通过_01访问01和02' 50 TabOrder = 3 51 OnClick = Button4Click 52 end 53 object Button5: TButton 54 Left = 16 55 Top = 232 56 Width = 185 57 Height = 25 58 Caption = 'Button5_访问01和02' 59 TabOrder = 4 60 OnClick = Button5Click 61 end 62 object Button6: TButton 63 Left = 384 64 Top = 88 65 Width = 75 66 Height = 25 67 Caption = 'Button6' 68 TabOrder = 5 69 OnClick = Button6Click 70 end 71 end