各位高手快来指点一下,是关于动态创建组件的!我现在接到一个任务,就是要动态创建组件,一般的组件还好,我想问的是如何在动态创建的Groupbox上在创建一个Edit 或button?请大家指点我一下!!我有很多分,一二百分没问题!

解决方案 »

  1.   

    var
    Groupbox1:TGroupbox;
    edit1:Tedit;
    Begin
      Groupbox1:=TGroupbox.create(self);
      Groupbox1.caption:='Groupbox1';
      Groupbox1.Name:='Groupbox1';
      Groupbox1.LEFT:=100;
      Groupbox1.TOP:=100;  
     
      Edit1:=Tedit1.create(self);
      edit1.caption:='edit1';
      edit1.name:='edit1';
       edit1.LEFT:=100;
      edit1.TOP:=100;  
    edit1.bringtofront;
    end;
      

  2.   

    : flyingkiller(大飞虫
    你说的那个到是好解决!
      

  3.   

    : Gongshl(阿单) Delphi中有控件数组吗?怎么用?
      

  4.   

    Edit 或button创建后,它们的parent设为Groupbox
      

  5.   

    procedure TForm1.FormCreate(Sender: TObject);
    VAr
      a:TGroupBox;
      b: TButton;
    begin
       a:=TGroupBox.Create(self);
       a.Parent:=self;
       a.Left:=80;
       a.Top:=60;
       b:=TButton.Create(self);
     b.Parent:=a;
    end;
      

  6.   

    控件数组可以看作一个普通类型的数组,用起来相当方便,还有,动态创建的控件要指定其parent.定位时可以指定其与parent的相对位置.
      

  7.   

    例:
    var 
      i:integer;
      myedit:array of TEdit;
    begin
      setlength(myedit,10);
      for i:=0 to 9 do
      begin
        myedit[i]:=TEdit.Create(self);
        myedit[i].parent=panel1;
        myedit[i].left=...
        ......  end;
    end;
      

  8.   

    同意: siyu2002
    procedure TForm1.FormCreate(Sender: TObject);
    VAr
      a:TGroupBox;
      b: TButton;
    begin
       a:=TGroupBox.Create(self);
       a.Parent:=self;
       a.Left:=80;
       a.Top:=60;
       a.width:=100;
       a.height:=100;
       b:=TButton.Create(self);  
       b.Parent:=a;
       
       b.Left:=80;
       b.Top:=60;
       b.width:=100;
       b.height:=100;
       
    end;