我想要用for语句实现动态生成Tcombobox控件
以及访问他的属性
请问该用什么办法?

解决方案 »

  1.   

    var
      aCom : TCombobox;
    begin
      aCom :=TCombobox.create(nil);
      aCom.portopen := true;
      aCom.free;
    end;
      

  2.   

    coolfilm(苏飞工作室),你这只是动态生成一个啊?
      

  3.   

    type
      CbBoxArr:array[0..9]of TCombobox;
    for i:=Low(CbBoxArr) to High(CbBoxArr) do
    begin
      CbBoxArr[i]:=TCombobox.Create(self);
      with CbBoxArr[i] do
       begin
        Parent:=Form1;
        //设置其他属性,诸如 位置,Items等等
       end;
    end;
    //////////在合适的地方。释放掉他们
    for i:=Low(CbBoxArr) to High(CbBoxArr) do
    begin
      CbBoxArr[i].Free
    end;
      

  4.   

    //为了方便我将COMBOBOX放在一个动态数组中。以下代码没有经过调试,你看看如果你明白就行。
    i:integer;
      tc:array of Tcombobox;
    begin
      setlength(tc,20);
      for i:= low(tc) to high(tc) do
      begin
      tc[i]:=Tcombobox.create(self);
      tc[i].name:='tc'+inttostr(i);
      tc[i].left:=i*30;
      tc[i].top:=20;
      tc[i].parent:=form1;///form1是你的窗体名
      tc[i].visible:=true;
      tc[i].tag:=i;
      end;
    end;
    访问更简单。
     tc[1].items.add('ddd');
    和普通填加的控件一样,虽然是数组的,但是你可以根据他们的TAG值或者名称不同而获取不同的数组中的COMBOBOX。并对其进行操作。这个很简单。
      

  5.   

    这是我自己写的,但是却不知如何访问
    var
      b:Tcombobox;
      n:integer;
    begin
    for n:=0 to 10 do
    begin
     b:=Tcombobox.Create(form1);
     b.Left:=20;
     b.Top:=n*20;
     b.Name:='a'+inttostr(n);
     b.Text:='';
     b.Parent:=Form1;
    end;
      

  6.   

    同一个东西,你做10次CREATE干什么???????????
    上面的代码看不明白么?????方法都在那里了。。
      

  7.   

    知道了,谢谢 SydPink(希望不再敲键盘!) duhailee(阿牛) 
      

  8.   

    不能读取combobox的text属性啊!!!