control '' has no parent window ( 积分: 50 )

  • 主题发起人 主题发起人 fengxiaoxiao
  • 开始时间 开始时间
F

fengxiaoxiao

Unregistered / Unconfirmed
GUEST, unregistred user!
正在做一个控件,可是报错:control '' has no parent window。
代码如下:
TPingZheng = class(TWinControl)
private
{ Private declarations }
FLabel1:Tlabel;
FPanel1:TPanel;
FCombobox1:TCombobox;
FHeight,FWidth:integer;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;


constructor TPingZheng.Create(AOwner: TComponent);
begin
inherited create(AOwner);

FWidth:=600;
FHeight:=200;

self.Width :=FWidth;
self.Height :=FHeight;

fpanel1:=tpanel.Create(self);
fpanel1.Color :=rgb(255,255,255);
fpanel1.Width :=FWidth;
fpanel1.Height :=FHeight;
fpanel1.Parent :=self;

fcombobox1:=tcombobox.Create(fpanel1);
fcombobox1.Top :=30;
fcombobox1.Left :=80;
fcombobox1.Parent :=fpanel1 ; //这里不是指定父控件了吗
fcombobox1.Items.Clear ; /////报错:control '' has no parent window
fcombobox1.Items.Add('记字') ;
fcombobox1.Items.Add('转字');
end;

将上述代码放到form的button中,可得到正确结果。
 
正在做一个控件,可是报错:control '' has no parent window。
代码如下:
TPingZheng = class(TWinControl)
private
{ Private declarations }
FLabel1:Tlabel;
FPanel1:TPanel;
FCombobox1:TCombobox;
FHeight,FWidth:integer;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;


constructor TPingZheng.Create(AOwner: TComponent);
begin
inherited create(AOwner);

FWidth:=600;
FHeight:=200;

self.Width :=FWidth;
self.Height :=FHeight;

fpanel1:=tpanel.Create(self);
fpanel1.Color :=rgb(255,255,255);
fpanel1.Width :=FWidth;
fpanel1.Height :=FHeight;
fpanel1.Parent :=self;

fcombobox1:=tcombobox.Create(fpanel1);
fcombobox1.Top :=30;
fcombobox1.Left :=80;
fcombobox1.Parent :=fpanel1 ; //这里不是指定父控件了吗
fcombobox1.Items.Clear ; /////报错:control '' has no parent window
fcombobox1.Items.Add('记字') ;
fcombobox1.Items.Add('转字');
end;

将上述代码放到form的button中,可得到正确结果。
 
http://delphibbs.com/delphibbs/dispq.asp?lid=109094

http://delphibbs.com/delphibbs/dispq.asp?lid=1686181

http://delphibbs.com/delphibbs/modifyl.asp?lid=387955

http://delphibbs.com/delphibbs/modifyl.asp?lid=1255970

http://delphibbs.com/delphibbs/modifyl.asp?lid=2151146

看看能搞定不了,里面说了什么原因引起的,也说了怎么解决的
 
接受答案了.
 
后退
顶部