无 无用书生 Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-09 #1 在DELPHI(我用的是5.0)有没有象VB中的控件数组的概念?如有怎样使用它?
P pyh_jerry Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-09 #2 可以啊,我刚刚用过。:) type a:array of timage; var b:a; …… begin b[1].create(self); b[1].parent:=form1; b[1].picture.loadfromfile('1.jpg'); end; …… begin if assigned b[1] then b[1].destroy; end;
可以啊,我刚刚用过。:) type a:array of timage; var b:a; …… begin b[1].create(self); b[1].parent:=form1; b[1].picture.loadfromfile('1.jpg'); end; …… begin if assigned b[1] then b[1].destroy; end;
教 教父 Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-09 #3 TWinControl有个Controls属性,它就是一个控件数组。
B BaKuBaKu Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-09 #4 var BtnList: array [0..X] of TControl; begin BtnList[0] := TButton.Create(Self); BtnList[1] := TCheckBox.Create(Self); ... end;
var BtnList: array [0..X] of TControl; begin BtnList[0] := TButton.Create(Self); BtnList[1] := TCheckBox.Create(Self); ... end;
J JohnsonGuo Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-09 #5 建议使用TObjectList,非常好用的说。
J JohnsonGuo Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-10 #7 For example type TForm1 = class(TForm) ... private List: TObjectList; end; procedure TForm1.FormCreate(...); begin List := TObjectList.Create; ... end; procedure TForm1.FormClose(...); begin List.Free; //All buttons in the list would be freed ... end; ... begin Btn := TButton.Create(Self); with Btn do begin Parent := Self; ... end; List.Add(Btn); ... end;
For example type TForm1 = class(TForm) ... private List: TObjectList; end; procedure TForm1.FormCreate(...); begin List := TObjectList.Create; ... end; procedure TForm1.FormClose(...); begin List.Free; //All buttons in the list would be freed ... end; ... begin Btn := TButton.Create(Self); with Btn do begin Parent := Self; ... end; List.Add(Btn); ... end;
J JohnsonGuo Unregistered / Unconfirmed GUEST, unregistred user! 2000-11-11 #10 在VB中的控件数组是通过Index属性实现的。但Delphi中没有相应的属性。但Delphi有自己 的方法:对要作类似VB的控件组在Object Inspector中设置相同的事件响应过程。 为每个控件设置合适的Tag属性(用于适别,如果控件的名字取得好的话,也可以直接用 Name, Caption属性进行适别)。 下面举一个类型计算器键盘的例子: object Form1: TForm1 Left = 262 Top = 81 Width = 119 Height = 221 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 12 Top = 12 Width = 89 Height = 21 Alignment = taRightJustify AutoSize = False Color = clYellow ParentColor = False Layout = tlCenter end object Button0: TButton Left = 44 Top = 64 Width = 25 Height = 25 Caption = '0' TabOrder = 0 OnClick = NumberBtnClick end object Button1: TButton Left = 12 Top = 96 Width = 25 Height = 25 Caption = '1' TabOrder = 1 OnClick = NumberBtnClick end object Button2: TButton Left = 44 Top = 96 Width = 25 Height = 25 Caption = '2' TabOrder = 2 OnClick = NumberBtnClick end object Button3: TButton Left = 76 Top = 96 Width = 25 Height = 25 Caption = '3' TabOrder = 3 OnClick = NumberBtnClick end object Button4: TButton Left = 12 Top = 128 Width = 25 Height = 25 Caption = '4' TabOrder = 4 OnClick = NumberBtnClick end object Button5: TButton Left = 44 Top = 128 Width = 25 Height = 25 Caption = '5' TabOrder = 5 OnClick = NumberBtnClick end object Button6: TButton Left = 76 Top = 128 Width = 25 Height = 25 Caption = '6' TabOrder = 6 OnClick = NumberBtnClick end object Button7: TButton Left = 12 Top = 160 Width = 25 Height = 25 Caption = '7' TabOrder = 7 OnClick = NumberBtnClick end object Button8: TButton Left = 44 Top = 160 Width = 25 Height = 25 Caption = '8' TabOrder = 8 OnClick = NumberBtnClick end object Button9: TButton Left = 76 Top = 160 Width = 25 Height = 25 Caption = '9' TabOrder = 9 OnClick = NumberBtnClick end end 代码如下: procedure TForm1.NumberBtnClick(Sender: TObject); begin Label1.Caption := Label1.Caption + (Sender as TButton).Caption; end;
在VB中的控件数组是通过Index属性实现的。但Delphi中没有相应的属性。但Delphi有自己 的方法:对要作类似VB的控件组在Object Inspector中设置相同的事件响应过程。 为每个控件设置合适的Tag属性(用于适别,如果控件的名字取得好的话,也可以直接用 Name, Caption属性进行适别)。 下面举一个类型计算器键盘的例子: object Form1: TForm1 Left = 262 Top = 81 Width = 119 Height = 221 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 12 Top = 12 Width = 89 Height = 21 Alignment = taRightJustify AutoSize = False Color = clYellow ParentColor = False Layout = tlCenter end object Button0: TButton Left = 44 Top = 64 Width = 25 Height = 25 Caption = '0' TabOrder = 0 OnClick = NumberBtnClick end object Button1: TButton Left = 12 Top = 96 Width = 25 Height = 25 Caption = '1' TabOrder = 1 OnClick = NumberBtnClick end object Button2: TButton Left = 44 Top = 96 Width = 25 Height = 25 Caption = '2' TabOrder = 2 OnClick = NumberBtnClick end object Button3: TButton Left = 76 Top = 96 Width = 25 Height = 25 Caption = '3' TabOrder = 3 OnClick = NumberBtnClick end object Button4: TButton Left = 12 Top = 128 Width = 25 Height = 25 Caption = '4' TabOrder = 4 OnClick = NumberBtnClick end object Button5: TButton Left = 44 Top = 128 Width = 25 Height = 25 Caption = '5' TabOrder = 5 OnClick = NumberBtnClick end object Button6: TButton Left = 76 Top = 128 Width = 25 Height = 25 Caption = '6' TabOrder = 6 OnClick = NumberBtnClick end object Button7: TButton Left = 12 Top = 160 Width = 25 Height = 25 Caption = '7' TabOrder = 7 OnClick = NumberBtnClick end object Button8: TButton Left = 44 Top = 160 Width = 25 Height = 25 Caption = '8' TabOrder = 8 OnClick = NumberBtnClick end object Button9: TButton Left = 76 Top = 160 Width = 25 Height = 25 Caption = '9' TabOrder = 9 OnClick = NumberBtnClick end end 代码如下: procedure TForm1.NumberBtnClick(Sender: TObject); begin Label1.Caption := Label1.Caption + (Sender as TButton).Caption; end;
C ccweifen Unregistered / Unconfirmed GUEST, unregistred user! 2000-12-01 #12 我在用ReportBuilder做报表,它里面的控件不能指定Parent属性, 如 Parent:=form1,它会提示'parent为只读的.',如何解决?
M mywanqi Unregistered / Unconfirmed GUEST, unregistred user! 2000-12-01 #13 建立数组控件时有大部分可视控件需要在XXXX.Create(填入self或者父控件名,如:Form1 或Panle1) 同时指定XXXX.Parent:=self或者父控件名。 如果控件要使用事件如: Button控件被单击后执行某段程序,就应该将 Button.Click:=指向一段已经声明的过程。 如果要 操作数组中的某个控件可以使用 With sender as TButton do //sender为过程参数; caption:='XXXXXXX'; end; 上述程序可以改变选中的按钮的标题名称!
建立数组控件时有大部分可视控件需要在XXXX.Create(填入self或者父控件名,如:Form1 或Panle1) 同时指定XXXX.Parent:=self或者父控件名。 如果控件要使用事件如: Button控件被单击后执行某段程序,就应该将 Button.Click:=指向一段已经声明的过程。 如果要 操作数组中的某个控件可以使用 With sender as TButton do //sender为过程参数; caption:='XXXXXXX'; end; 上述程序可以改变选中的按钮的标题名称!