我想开发一个ToolBar组件。要求ToolButton个数和图标都固定,点击ToolButton执行相应的程序或表单。编写的组件出错误" Control '' has no parent window! "。代码如下:
unit MyTLB;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ToolWin, ComCtrls;
type
TMyTLB = class(TToolBar)
private
{ Private declarations }
fTB:TToolButton;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
constructor TMyTLB.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fTB:=TToolButton.Create(Self);
fTB.Parent:=Self;//可能主要在这个地方出错,应该怎么办?
fTB.Update
end;
destructor tmytlb.destroy;
begin
ftb.free;
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('Templates', [TMyTLB]);
end;
end.
unit MyTLB;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ToolWin, ComCtrls;
type
TMyTLB = class(TToolBar)
private
{ Private declarations }
fTB:TToolButton;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
constructor TMyTLB.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fTB:=TToolButton.Create(Self);
fTB.Parent:=Self;//可能主要在这个地方出错,应该怎么办?
fTB.Update
end;
destructor tmytlb.destroy;
begin
ftb.free;
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('Templates', [TMyTLB]);
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货