对10个下拉菜单做相同操作 ,我想用
var Mycombobox:Tcombobox;
for i:=1 to 10 do
//下面怎么让Mycombobox代表combobox1、2、3...
//

解决方案 »

  1.   

    除非你名字有共性,比如
    combox1
    combox2
    combox3
    combox4
    combox5
    combox6
    这样排下去的,
    那么可以用findcomponent('combox' + inttostr(i))来完成
      

  2.   

    否则用
    for i := 0 to self.componentcount - 1 do
    begin
      if self.components[i] is tcombobox then
      begin
        showmessage(inttostr((self.components[i] as tcombobox).itemindex)));
      end;
    end;
      

  3.   


    for i:=1 to 10 do
    begin
      with DataModule1.gy_table1 do
      begin
      close;
      sql.clear;
      sql.add('select * from kemu_table');
      open;
      Tcombobox(FindComponent('kemu'+inttostr(i))).Items.Clear;
        while not eof do
        begin
        Tcombobox(FindComponent('kemu'+inttostr(i))).Items.Add(fieldbyname('kemu').AsString);
        end;
      end;
    end;
    是这样?不行呀,运行出错
      

  4.   

    你combox的名字是
    kemu1
    kemu2
    ....
    kemu10吗?
      

  5.   

    我没加next ,呵呵,谢谢,没错,是我自己代码有问题