在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;
[解决办法]
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;
[解决办法]
修订下
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;
[解决办法]
unit Unit1;interfaceuses 。。。。。。;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.