delphi 如何为自定义组件加类似combobox的items属性?
展开全部
随便给你写了一个例子,不太好,不过可以说明问题!unit
Button1;interfaceuses
Windows,
Messages,
SysUtils,
Classes,
Controls,
StdCtrls;type
TMyButton
=
class(TButton)
private
Fstr:TstringList;
procedure
SetStr(Str:TstringList);
protected
constructor
Create(Aowner:Tcomponent);override;
destructor
Destroy;override;
public
published
property
items
:TstringList
read
Fstr
write
SetStr;
end;procedure
Register;implementationconstructor
TMyButton.Create(Aowner:Tcomponent);
begin
inherited
Create(Aowner);
if
Not
assigned(Fstr)
then
Fstr:=TstringList.Create;
end;destructor
TMyButton.Destroy;
begin
if
assigned(Fstr)
then
Fstr.Free;
inherited
Destroy;
end;procedure
TMyButton.SetStr(Str:TstringList);
begin
if
assigned(Fstr)
then
Fstr.Assign(Str);
end;procedure
Register;begin
RegisterComponents('LZJ',
);end;end.
Button1;interfaceuses
Windows,
Messages,
SysUtils,
Classes,
Controls,
StdCtrls;type
TMyButton
=
class(TButton)
private
Fstr:TstringList;
procedure
SetStr(Str:TstringList);
protected
constructor
Create(Aowner:Tcomponent);override;
destructor
Destroy;override;
public
published
property
items
:TstringList
read
Fstr
write
SetStr;
end;procedure
Register;implementationconstructor
TMyButton.Create(Aowner:Tcomponent);
begin
inherited
Create(Aowner);
if
Not
assigned(Fstr)
then
Fstr:=TstringList.Create;
end;destructor
TMyButton.Destroy;
begin
if
assigned(Fstr)
then
Fstr.Free;
inherited
Destroy;
end;procedure
TMyButton.SetStr(Str:TstringList);
begin
if
assigned(Fstr)
then
Fstr.Assign(Str);
end;procedure
Register;begin
RegisterComponents('LZJ',
);end;end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询