procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
for i:=0 to form1.ComponentCount-1 do
begin
if form1.Components[i] is tcombobox then
TCombobox(form1.Components[i]).Items.Add('d'); end;
end;
var i,j:integer;
begin
for i:=0 to form1.ComponentCount-1 do
begin
if form1.Components[i] is tcombobox then
TCombobox(form1.Components[i]).Items.Add('d'); end;
end;
begin
TComboBox(FindComponent('combobox'+inttostr(iCount))).Items.Add('aaa');
end;
var i,j:integer;
begin
for i:=0 to form1.ComponentCount-1 do
begin
if form1.Components[i] is tcombobox then
if form1.components[i].parent.name := 'sheet1' then //再判断一下
TCombobox(form1.Components[i]).Items.Add('d'); end;
end;
只要加一个判断component的parent的语句
if Components[i] is TComboBox then
Components[i] as TComboBox).Items.Add('XXX');