在delphi中,小弟我要向某函数同时传递一批不同类型的控件,如TEDIT、TButton、Tcheckbox控件,而且个数不定,如何实现
在delphi中,我要向某函数同时传递一批不同类型的控件,如TEDIT、TButton、Tcheckbox控件,而且个数不定,怎么实现
在delphi中,我要向某函数同时传递一批不同类型的控件,如TEDIT、TButton、Tcheckbox控件,怎么实现
具体如下:
我要向aaa函数传递aaa([edt1,btn1,chk1],visible,true),函数就这三个参数,怎么实现,而且第一个参数可变,
要求aaa函数实现以下功能:
edt1.visible :=true;
btn1.visible :=true;
chk1.visible :=true;
求大虾帮忙,我一定送分!!
------解决方案--------------------
怎么还要传入visible即属性?属性名不能当参数
------解决方案--------------------
还有,你传入的属性是TControl有的吗?
------解决方案--------------------
如果是,那你第一个参数可用:array of Tcontrol
------解决方案--------------------
const Array of T;
使用const修饰的数组参数可以使用实参数组
------解决方案--------------------
procedure aaa(var a:array of TWinControl;b:boolean);
var i:integer;
begin
for i:=low(a) to high(a) do
a[i].visible:=b;
end;
------解决方案--------------------
在delphi中,我要向某函数同时传递一批不同类型的控件,如TEDIT、TButton、Tcheckbox控件,怎么实现
具体如下:
我要向aaa函数传递aaa([edt1,btn1,chk1],visible,true),函数就这三个参数,怎么实现,而且第一个参数可变,
要求aaa函数实现以下功能:
edt1.visible :=true;
btn1.visible :=true;
chk1.visible :=true;
求大虾帮忙,我一定送分!!
------解决方案--------------------
怎么还要传入visible即属性?属性名不能当参数
------解决方案--------------------
还有,你传入的属性是TControl有的吗?
------解决方案--------------------
如果是,那你第一个参数可用:array of Tcontrol
------解决方案--------------------
const Array of T;
使用const修饰的数组参数可以使用实参数组
------解决方案--------------------
procedure aaa(var a:array of TWinControl;b:boolean);
var i:integer;
begin
for i:=low(a) to high(a) do
a[i].visible:=b;
end;
------解决方案--------------------
- Delphi(Pascal) code
procedure aaa(x: array of TWinControl; b: Boolean); var i: Integer; begin for i := 0 to Length(x) do begin x[i].Visible := b; end; end;
------解决方案--------------------
修订下
- Delphi(Pascal) code
procedure aaa(x: array of TWinControl; b: Boolean); var i: Integer; begin for i := 0 to Length(x) -1 do begin x[i].Visible := b; end; end;
------解决方案--------------------
------解决方案--------------------
17 楼是正确的。
用下面代码试试就知道了:
- Delphi(Pascal) code
unit Unit1; interface uses 。。。。。。; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; CheckBox1: TCheckBox; Button2: TButton; Button3: TButton; procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } procedure aaa(x: array of TWinControl; b: Boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.aaa(x: array of TWinControl; b: Boolean); var i: Integer; begin for i := 0 to Length(x) -1 do x[i].Visible := b; end; procedure TForm1.Button2Click(Sender: TObject); begin aaa([Edit1,Button1,CheckBox1],false); end; procedure TForm1.Button3Click(Sender: TObject); begin aaa([Edit1,Button1,CheckBox1],true); end; end.