在 Delphi 中能动态创建组件(按钮)吗? 如果能请举例.

解决方案 »

  1.   

    with tbutton.create(self) do
    begin
      parent := self;
      caption := 'sdaf';
    end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      newbutton : TButton;
    begin
      newbutton := TButton.Create(self);
      newbutton.Parent := self;
      newbutton.Left := 100;
      newbutton.Top := 100;
      newbutton.Caption := 'newbutton';
    end;
      

  3.   

    var btn:Tbutton;
    begin
      btn:=Tbutton.Create(self);
      btn.Parent:=self;
      btn.Left:=100;
      btn.Top:=100;
      btn.Height:=100;
      btn.Width:=200;
      btn.Caption:='我是动态创建的';
      

  4.   

    谢谢!其它的组件也应该可以吧?我打算做一个通用窗口,有一个要多几个组件.而且那些组件又没有 visible 属性,所以我想动态创建.
      

  5.   

    声明    procedure bc(Sender: TObject);
    写事件代码
    procedure TForm1.bc(Sender: TObject);
    begin
      showmessage('ok');
    end;连接事件btn:Tbutton;
    begin
      btn:=Tbutton.Create(self);
      btn.Parent:=self;
      btn.Left:=100;
      btn.Top:=100;
      btn.Height:=100;
      btn.Width:=200;
      btn.Caption:='123';
      btn.OnClick:=bc;
      

  6.   

    同意zhaojinghui(撒哈拉之雨的悲伤)的说法!
    我迟到了!
    现在,我只好帮你顶
      

  7.   

    最好写在form.close事件里
    一般象什么数据集关闭时还有变量释放时都在这里写