先遍历窗体上的所有控件,不好意思,语句忘了,然后 if sender is Tradiobuttion then 判断 // 在这里给数组付值
就没有办法在form上摆控件的时候就把相关的设为一个数组吗 我记得是可以的,只是两年不用,忘完了
.tag 属性可以用于控件数组的使用。另外可以将控件的名称命名为 RBtn1 Rbtn2 RBtn3 ....然后使用FindComponent函数调用它们。例如:var i:integer; obj:TObject; begin for i:=1 to 10 do begin obj:=findcomponent('RBtn'+inttostr(i)); .....
.tag 的使用:var i:integer; obj:Tobject; begin for i:=0 to ComponentCount -1 do if (components[i].tag =10) and (components[i] is RadioButton) then begin obj:=components[i]; ........
不好意思, component[i] is RadioButton) 应该修改为component[i] is TRadioButton)
if sender is TRadioButton then case TRatioButton(sender).tag of 1: 2: end;
procedure TFrmTest.ChuangTiBiaoGeCreate(); var NewCheckBoxtTop:integer; i:integer; begin filename:=ExtractFilePath(paramstr(0))+'DBPZLIST.ini'; peizhilist:=Tinifile.create(filename); NewCheckBoxtTop:=0; for i:=1 to 30 do begin NEWCheckBox[i] := TcheckBox.create(self); NEWCheckBox[i].top := NewCheckBoxtTop+20 ; NEWCheckBox[i].Left := 8; NEWCheckBox[i].Width := 70; NEWCheckBox[i].Caption := DBGrid.Columns[i].Title.Caption ; Newcheckbox[i].Parent := GroupBox ; NewCheckBox[i].Checked := peizhilist.readbool('pz',NEWCheckBox[i].Caption,false); DBGrid.Columns[i].Visible :=newcheckbox[i].Checked ; NewCheckBoxtTop := NewCheckBoxtTop+20; end; end;
接上文,你自己参考一下吧 ... var NEWCheckBox: array[0..30] of TCheckBox ;//在前面声明一个数组 implementation ....
procedure TForm1.Button1Click(Sender: TObject); begin for I := 0 to Self.ComponentCount - 1do begin if (Self.FindComponent('StaticTextN')) is TStaticText then begin ((Self.FindComponent('StaticTextN')) as TStaticText).Caption := 'Caption'; ((Self.FindComponent('StaticTextN')) as TStaticText).Left := 100; ((Self.FindComponent('StaticTextN')) as TStaticText).Top := 200; //保存到数据库 end; end; end;------------------------------------ 这个例子可以看看,另外可以用tag属性
if sender is Tradiobuttion then 判断
// 在这里给数组付值
我记得是可以的,只是两年不用,忘完了
obj:TObject;
begin
for i:=1 to 10 do
begin
obj:=findcomponent('RBtn'+inttostr(i));
.....
obj:Tobject;
begin
for i:=0 to ComponentCount -1 do
if (components[i].tag =10) and (components[i] is RadioButton) then
begin
obj:=components[i];
........
case TRatioButton(sender).tag of
1:
2:
end;
var
NewCheckBoxtTop:integer;
i:integer;
begin
filename:=ExtractFilePath(paramstr(0))+'DBPZLIST.ini';
peizhilist:=Tinifile.create(filename);
NewCheckBoxtTop:=0;
for i:=1 to 30 do
begin
NEWCheckBox[i] := TcheckBox.create(self);
NEWCheckBox[i].top := NewCheckBoxtTop+20 ;
NEWCheckBox[i].Left := 8;
NEWCheckBox[i].Width := 70;
NEWCheckBox[i].Caption := DBGrid.Columns[i].Title.Caption ;
Newcheckbox[i].Parent := GroupBox ;
NewCheckBox[i].Checked := peizhilist.readbool('pz',NEWCheckBox[i].Caption,false);
DBGrid.Columns[i].Visible :=newcheckbox[i].Checked ;
NewCheckBoxtTop := NewCheckBoxtTop+20; end;
end;
...
var
NEWCheckBox: array[0..30] of TCheckBox ;//在前面声明一个数组
implementation
....
begin
for I := 0 to Self.ComponentCount - 1do
begin
if (Self.FindComponent('StaticTextN')) is TStaticText then
begin
((Self.FindComponent('StaticTextN')) as TStaticText).Caption := 'Caption';
((Self.FindComponent('StaticTextN')) as TStaticText).Left := 100;
((Self.FindComponent('StaticTextN')) as TStaticText).Top := 200;
//保存到数据库
end;
end;
end;------------------------------------
这个例子可以看看,另外可以用tag属性
用tag做下标也行