功能:在COOLBAR上放TOOLBAR,再在TOOLBAR上放TOOLBUTTON;
在编写的过程中在D6上编译时出现
control '' has no parent window
错误!请各位帮助改正,谢谢!
内容如下:
unit CoolTooBarButton;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolWin, ComCtrls, StdCtrls, DB, Buttons, DBCtrls;type
  TToolBtn = (tbInsert,tbDelete,tbUpdate,tbSave,tbCancel);
  TToolButtonSet = Set of TToolBtn;
  TCoolToolBarButton = class(TWinControl)
  private
    CoolBar:TCoolBar;
    ToolBar:TToolBar;
    ToolButton:TToolButton;
    FDataSet: TDataSet;
    FVisibleButtons: TToolButtonSet;
    FToolBarVisible: Boolean;
    procedure InitButtons;
    procedure AddButtons(ToolBar:TToolBar;const ButtonCaptions:Array of String);
    procedure SetDataSet(const Value: TDataSet);
    function CheckDataSet:Boolean;
    procedure SetVisibleButtons(const Value: TToolButtonSet);
    procedure SetToolBarVisible(const Value: Boolean);
    { Private declarations }
  protected
    { Protected declarations }
    ToolBtns:array [TToolBtn] of TToolButton;
  public
    { Public declarations }
    constructor Create(AOwner:TComponent);override;
    destructor Destroy;override;
  published
    { Published declarations }
  property Align default alTop;
  property DataSet:TDataSet read FDataSet write SetDataSet;
  property ToolBarVisible:Boolean read FToolBarVisible write SetToolBarVisible;
  property VisibleButtons:TToolButtonSet read FVisibleButtons write SetVisibleButtons default [tbInsert,tbDelete,tbUpdate,tbSave,tbCancel];
  end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('zfb', [TCoolToolBarButton]);
end;{ TCoolTooBarButton }procedure TCoolToolBarButton.AddButtons(ToolBar: TToolBar;
  const ButtonCaptions: array of String);
var
    I:Integer;
begin
 for I := High(ButtonCaptions) Downto 0 do
    begin
      with TToolButton.Create(Self) do
      begin
        Parent := ToolBar;
        Height:=ToolBar.Height;
        Caption := ButtonCaptions[I];
        if (ButtonCaptions[I] = '|') then
          Style := tbsSeparator
        else
          Style := tbsButton;
      end;
    end;end;function TCoolToolBarButton.CheckDataSet: Boolean;
begin
if FDataSet<>nil then Result:=true
else Result:=false;
end;constructor TCoolToolBarButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FVisibleButtons:=[tbInsert,tbDelete,tbUpdate,tbSave,tbCancel];
  Align:=alTop;
  //if (csDesigning in ComponentState) then
  //begin
  CoolBar:=TCoolBar.Create(Self);
  CoolBar.Parent:=Self;
  CoolBar.Height:=75;
  CoolBar.AutoSize:=false;  ToolBar:=TToolBar.Create(Self);
  ToolBar.Parent:=CoolBar;//Self
  ToolBar.Height:=75;//CoolBar.Height;
  ToolBar.AutoSize:=false;   AddButtons(ToolBar,['ADD','|','Delete','|','Update','|','Save','|','Cancel']);
 { ToolButton:=TToolButton.Create(Self);
  with ToolButton do
  begin
  Caption:='Add';
  Height:=75;
  Style:=tbsButton;
  visible:=true;
  end;  }
  ToolBar.ShowCaptions := True; // end;end;destructor TCoolToolBarButton.Destroy;
begin
  ToolBar.Free;
  CoolBar.Free;
  inherited Destroy;
end;procedure TCoolToolBarButton.InitButtons;
var
I:TToolBtn;
Btn:TToolButton;
begin
for I:=Low(TToolBtn) to High(TToolBtn) do
begin
    Btn:=TToolButton.Create(Self);
    Btn.Parent:=CoolBar;
    Btn.Style:=tbsButton;
    //Btn.Index:=I;
    Btn.AutoSize:=true;
    Btn.Visible:=I in FVisibleButtons;
    Btn.Enabled:=true;
    Btn.Caption:='Add';end;
end;procedure TCoolToolBarButton.SetDataSet(const Value: TDataSet);
begin
if FDataSet<>Value then
   FDataSet:=Value;
end;procedure TCoolToolBarButton.SetToolBarVisible(const Value: Boolean);
begin
if FToolBarVisible<>Value then
  FToolBarVisible := Value;
ToolBar.Visible:=Value;
end;procedure TCoolToolBarButton.SetVisibleButtons(
  const Value: TToolButtonSet);
begin
if FVisibleButtons<>Value then
  FVisibleButtons := Value;
end;end.