S
samuelzhu
Unregistered / Unconfirmed
GUEST, unregistred user!
自定义控件中有一Tlistview控件,希望在生成控件时,往TlistView加一些项目,
但调用Tlistitem时,出错:control '' has no parent window
请问是何原因? 如何往里面加项目?
程序附后
unit test;
interface
uses
Windows, Messages, Classes, Graphics, ComCtrls, Controls, StdCtrls, ExtCtrls;
type
Ttest = class(TcustomControl)
private
ListView1: TListView;
protected
procedure FillInListView;
public
Constructor Create(Aowner: Tcomponent); Override;
Destructor Destroy; Override;
published
end;
procedure Register;
implementation
Constructor Ttest.Create(Aowner: Tcomponent);
begin
Inherited Create(Aowner);
ListView1:=Tlistview.Create(self);
with ListView1 do begin
Parent :=self;
ViewStyle := vsReport;
Top :=3;
Left :=3;
height:=200;
end;
FillInListView;
end;
Destructor Ttest.Destroy;
Begin
ListView1.Free ;
Inherited Destroy;
End;
procedure Ttest.FillInListView;
var ListItem: TListItem;
begin
ListItem := ListView1.Items.Add;//出错信息为:control '' has no parent window
Listitem.Caption :='test';
end;
procedure Register;
begin
RegisterComponents('Samples', [Ttest]);
end;
end.
但调用Tlistitem时,出错:control '' has no parent window
请问是何原因? 如何往里面加项目?
程序附后
unit test;
interface
uses
Windows, Messages, Classes, Graphics, ComCtrls, Controls, StdCtrls, ExtCtrls;
type
Ttest = class(TcustomControl)
private
ListView1: TListView;
protected
procedure FillInListView;
public
Constructor Create(Aowner: Tcomponent); Override;
Destructor Destroy; Override;
published
end;
procedure Register;
implementation
Constructor Ttest.Create(Aowner: Tcomponent);
begin
Inherited Create(Aowner);
ListView1:=Tlistview.Create(self);
with ListView1 do begin
Parent :=self;
ViewStyle := vsReport;
Top :=3;
Left :=3;
height:=200;
end;
FillInListView;
end;
Destructor Ttest.Destroy;
Begin
ListView1.Free ;
Inherited Destroy;
End;
procedure Ttest.FillInListView;
var ListItem: TListItem;
begin
ListItem := ListView1.Items.Add;//出错信息为:control '' has no parent window
Listitem.Caption :='test';
end;
procedure Register;
begin
RegisterComponents('Samples', [Ttest]);
end;
end.