W
wind_2005
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个复合控件,里面包含了一个Panel,一个ToolBar,ToolBar上有一个ToolButton,但是加载控件时出现异常,请各位高人帮帮我,谢谢!代码如下:unit winControl1;interfaceuses SysUtils, Classes, Controls,ComCtrls,ExtCtrls;type twinControl1 = class(TWinControl) private { Private declarations } tb: TToolBar; pa: TPanel; ToolButton1: TToolButton; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; published { Published declarations } end;procedure Register;implementationprocedure Register;begin RegisterComponents('TAMS', [twinControl1]);end;{ twinControl1 }constructor twinControl1.Create(AOwner: TComponent);begin inherited; pa := TPanel.Create(Self); pa.Parent := Self; pa.Align := alClient; tb := TToolBar.Create(pa); tb.Parent := pa; //如果没有下面两句,就会正常 ToolButton1 := TToolButton.Create(tb); ToolButton1.Parent := tb;end;destructor twinControl1.Destroy;begin pa.Free; tb.Free; ToolButton1.Free; inherited;end;end.