这个问题我问了好几次了,也有好些热心的人帮过我,但最终还是没解决:
也许你一看就会:
... i : integer; ComboBox12 : TComboBox; ... i := 2 我如何才能将变量"i"用在ComboBox12的名字中?也就是说用变量"i"去替代"ComboBox12"中的"2"?
我要访问这个组件下的属性,而我又不能指明具体是哪个组件,也就是说当i = 2的时候,我就要访问ComboBox12里的某个属性,当i = 3的时候呢,我就想访问ComboBox13里的某个属性,
这该如何处理啊?对于高手来说,这个问题应该不难吧?
也许你一看就会:
... i : integer; ComboBox12 : TComboBox; ... i := 2 我如何才能将变量"i"用在ComboBox12的名字中?也就是说用变量"i"去替代"ComboBox12"中的"2"?
我要访问这个组件下的属性,而我又不能指明具体是哪个组件,也就是说当i = 2的时候,我就要访问ComboBox12里的某个属性,当i = 3的时候呢,我就想访问ComboBox13里的某个属性,
这该如何处理啊?对于高手来说,这个问题应该不难吧?
FcType : TComponent;
begin
FcType := FindComponent('edit'+'1') ; showmessage( tedit( fctype).text);
end;
1.用FindComponent函数:
procedure TfrmMain.Button2Click(Sender: TObject);
var
i: Word;
cmpTemp: TComponent;
begin
//i赋值
cmpTemp := FindComponent('ComboBox'+IntToStr(i));
//other code
end;
2.用组件的Tag属性:
如果这是组件是设计期就设计好了的,
你可以给其Tag属性赋上一些特定的值(初始值为0)
再根据Tag的值进行处理:
for i := 0 to ComponentCount-1 do
begin
if (Components[i] is TQRShape)and(Components[i].Tag = 10) then //10: 竖线
begin
(Components[i] as TQRShape).Height := DetailBand1.Height;
end;
if (Components[i] is TQRShape)and(Components[i].Tag = 20) then //20: 横线
begin
(Components[i] as TQRShape).Top := DetailBand1.Height-2;
end;
if (Components[i] is TQRDBText)and(Components[i].Tag = 30) then //30: TQRDBText
begin
(Components[i] as TQRDBText).Enabled := (Components[i] as TQRDBText).DataSet.FieldByName((Components[i] as TQRDBText).DataField).AsInteger <> 0;
end;
end;