T
tadpoleplus
Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义一个组件,对组件内的一个对像初始化时ToolButton1.Parent:=self;为什么出错?小弟刚开始学习组件,请各位老大指点。谢谢。
程序:
============自定义组件 (其实就是自定义一个工具条,在画工具条里的按钮时出错。)
unit UToolBar;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ToolWin,ComCtrls;
type
TToolBar1 = class(TToolBar)
private
ToolButton1: TToolButton;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PKTool', [TToolBar1]);
end;
{ TToolBar1 }
constructor TToolBar1.Create(AOwner: TComponent);
begin
inherited;
ToolButton1:=TToolButton.Create(Self);
ToolButton1.Height:=220;
ToolButton1.Left:=0;
ToolButton1.Top:=2;
ToolButton1.Width:=230;
ToolButton1.Parent:=self; <-----------这儿出错,好像说传入的self不 是TWinControl对像?
end;
destructor TToolBar1.Destroy;
begin
inherited;
end;
end.
========测试用FORM。
. . . . . .
. . . . . .
. . . . . .
uses UToolBar;
var
TestTToolBar:TToolBar1;
{$R *.dfm}
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
TestTToolBar:=TToolBar1.Create(Self);
TestTToolBar.Height:=29;
TestTToolBar.Width:=536;
TestTToolBar.Top:=0;
TestTToolBar.Left:=0;
TestTToolBar.Parent:=self;
TestTToolBar.Visible:=true;
end;
程序:
============自定义组件 (其实就是自定义一个工具条,在画工具条里的按钮时出错。)
unit UToolBar;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ToolWin,ComCtrls;
type
TToolBar1 = class(TToolBar)
private
ToolButton1: TToolButton;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PKTool', [TToolBar1]);
end;
{ TToolBar1 }
constructor TToolBar1.Create(AOwner: TComponent);
begin
inherited;
ToolButton1:=TToolButton.Create(Self);
ToolButton1.Height:=220;
ToolButton1.Left:=0;
ToolButton1.Top:=2;
ToolButton1.Width:=230;
ToolButton1.Parent:=self; <-----------这儿出错,好像说传入的self不 是TWinControl对像?
end;
destructor TToolBar1.Destroy;
begin
inherited;
end;
end.
========测试用FORM。
. . . . . .
. . . . . .
. . . . . .
uses UToolBar;
var
TestTToolBar:TToolBar1;
{$R *.dfm}
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
TestTToolBar:=TToolBar1.Create(Self);
TestTToolBar.Height:=29;
TestTToolBar.Width:=536;
TestTToolBar.Top:=0;
TestTToolBar.Left:=0;
TestTToolBar.Parent:=self;
TestTToolBar.Visible:=true;
end;