本人在动态建立组件时出现了错误,望大家帮忙
代码如下:
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.   

    TWidgetControl是Linux中使用的,在单元QStdCtrls中。对应WIndows应该用TWinControl。你去掉
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,QStdCtrls, ExtCtrls;
    中的QStdCtrls,—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  2.   

    问题解决了,感谢: breezing(网上的小鱼) 老兄,能请问一下这是为什么吗???
      

  3.   

    同时感谢lxpbuaa(桂枝香在故国晚秋)
      

  4.   

    楼上说的对,单元包含有问题,你不是用的CLX吧