本人在动态建立组件时出现了错误,望大家帮忙
代码如下:
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初学者,技术较菜,望指点迷津!!
代码如下:
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初学者,技术较菜,望指点迷津!!
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,QStdCtrls, ExtCtrls;
中的QStdCtrls,—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————