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中,可得到正确结果。
代码如下:
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中,可得到正确结果。