简单问题,答完就给50分!如何动态创建对象并显示在窗体中?

解决方案 »

  1.   

    with TButton.Create(Self) do
      begin
        Name := Button1 ;
        Top := 10 ;
        Left := 10 ;
        Width := 10 ;
        Height := 10 ;
        Parent := Form1 ;
      end;
      

  2.   

    例:
    var
      btn : Tbutton;
    begin
      btn := Tbutton.Create(Self);
      btn.Name := 'btn1';
      btn.Caption := '111';
      btn.Left := 100;
      btn.Top  := 100;
      btn.Parent:=form1;
    ....................
    end;
      

  3.   

    也可以是一数组
    var
     mm:array [0..100]of timage;
    begin
      mm[0]:=timage.create(self);
      mm[0].parent:=form1;
      mm[0].width:=;
      mm[0].height:=;
      mm[0].top:=;
      mm[0].left;=;end;
      

  4.   

    具体来说楼上的方法最好,还可以给它加上一个事件!mm[0].onclick := .....
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    var button2:tbutton;
    begin
      button2:=tbutton.Create(application);
      button2.Left:=50;
      button2.Top:=50;
      button2.Height:=25;
      button2.Width:=75;
      button2.Parent:=form1;
      button2.Caption:='你好!';
    end;