我是新手,哈哈。
请问如何在FORM中用代码创建一个按钮?并且能够在运行时将此按钮显示在窗口某个指定的位置?

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
         var
           a:tbutton;
         begin
           a:=tbutton.Create(self);
           with a do 
           begin
             Top:=100;
             Left:=100;
             Height:=20;
             Width:=100;
             Parent:=form1;
           end;
         end;
      

  2.   

    多谢。
    那同样的道理,我要自动创建一个Table1
    这样写:
    var
      Table1 : TTable;
      S : string;
    begin
      Table1 := TTable.Create(self);
    end;为什么编译时出错:“undeclared identifier TTable”?
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        Nums : integer ;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
     a:tbutton;
    begin
       a:=tbutton.Create(self);
       with a do
        begin
          Nums := Nums + 1 ;
          Top:=0 + Nums*Button1.Height ;
          Left:=100  ;
          Height:=Button1.Height ;
          Width:=Button1.Width ;
          name := 'Button'+IntToStr(Nums) ;
          Onclick := Button1Click;
          Parent:=form1;
       end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     Nums := 1 ;
    end;end.
      

  4.   

    procedure TForm1.FormCreate(Sender: TObject);
         var
           a:tbutton;
         begin
           a:=tbutton.Create(self);
           with a do 
           begin
             Top:=100;
             Left:=100;
             Height:=20;
             Width:=100;
             Parent:=form1;
           end;
         end;
      

  5.   

    uses DB;然后才有 TTABLE等BDE控件