unit cerc1;
     
     interface
     
     uses
     Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs ,stdctrls ;
     
     type
     TForm1 = class(TForm)
     
     private
     procedure frommousedown(sender: tobject; button: tmousebutton;
     shift: tshiftstate; x, y: integer);
     { Private declarations }
     public
     { Public declarations }
     end;
     
     var
     Form1: TForm1;
     
     implementation
     
     {$R *.dfm}
     
     procedure tForm1.frommousedown(sender:tobject; button:tmousebutton; shift:tshiftstate; x,y:integer);
     var
     btn:tbutton;
     begin
     btn:=tbutton.create(self);
     btn.Parent :=self;
     btn.top:=x;
     btn.left:=y;
     btn.Width:=btn.Width +30;
     btn.caption:=format('button at %d,%d',[x,y]);
     end;
     end.

解决方案 »

  1.   

    如果你是在Object Inspector上双击产生窗体的OnMouseDown事件过程的话,就和上面的代码不一样,就可以通过编译了。
      

  2.   

    btn.Width:=btn.Width +30;=>btn.Width:=30;
      

  3.   

    兄弟,这样改一下就可以了:    
      type
        TForm1 = class(TForm)
           procedure frommousedown(sender: tobject; button: tmousebutton;
             shift: tshiftstate; x, y: integer);
         
        private
           { Private declarations }
        public
           { Public declarations }
        end;
      

  4.   

    生成Button的例子:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      btn : TButton;
    begin
    Btn := TButton.Create(Self);
    with Btn do begin
      Parent := form1;
      Top := 50;
      Left := 50 ;
      Width := 50;
      Height := 50;
      Caption := 'Hello';
    end;end;end.
      

  5.   

    应该是
         btn.top:=y;
         btn.left:=x;