本人在动态建立组件时出现了错误,望大家帮忙
代码如下:
unit p42;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,QStdCtrls, ExtCtrls;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);
  btn.Parent:=Self;    //
  btn.left:=x;
  btn.top:=y;
  btn.width:=btn.width+50;
  btn.caption:=Format('Button at %d,%d',[x,y]);end;end.
敲F9运行时出现提示:
[Error]p42.pas(32):Incompatible types:'TWidgetControl' and 'TForm1'
[Fatal Error] p42pro.dpr(5):Could not compile used unit 'p42.pas'
难道这种动态创建组件的方法不对??因为本人为Delphi初学者,技术较菜,望指点迷津!!

解决方案 »

  1.   

    btn:=TButton.Create(application);
      btn.Parent:=Form1;
      

  2.   

    uses
      QStdCtrls ????
    你用的是CLX?
    应该是StdCtrls这个单元
      

  3.   

    QStdCtrls?你用CLX做什么?删除他。方法是正确的,没有问题呀!interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      btn:TButton;
    begin
      btn:=TButton.Create(Self);
      btn.Parent:=Self;    //
      btn.left:=x;
      btn.top:=y;
      btn.width:=btn.width+50;
      btn.caption:=Format('Button at %d,%d',[x,y]);
    end;end.