If you make the toolbar the owner of the tool button, you need to have a published property to be able to set its properties in the object inspector. This will also make it possible to free it later. The local variable in your code sample suggests this is not the case.
type
ZMyToolbart = class(TToolbar)
private
FHalloButton: TToolButton;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property HalloButton: TToolButton read FHalloButton write FHalloButton;
end;
constructor ZMyToolbart.Create(AOwner: TComponent);
begin
inherited;
Parent := Owner as TWinControl;
FHalloButton := TToolButton.Create(Self);
FHalloButton.Parent := Self;
FHalloButton.Caption := 'Hallo';
end;
destructor ZMyToolbart.Destroy;
begin
FHalloButton.Free;
inherited;
end;
This, probably, will not give you what you want, you'll see the button's properties in a sub-property in the OI, not like other buttons. If you want your button to appear like ordinary tool buttons, make its owner the form, not the toolbar.
Then the button will be selectable on its own. This also means the button might be deleted at design-time (as well as at run time), hence you'd want to be notified when it's deleted and set its reference to nil.
Finally, you only want to create the button at design-time, since at run-time the button will be stream-created from the .dfm and then you'll have two buttons.
And don't forget to register the button class:
type
ZMyToolbart = class(TToolbar)
private
FHalloButton: TToolButton;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
end;
[...]
constructor ZMyToolbart.Create(AOwner: TComponent);
begin
inherited;
Parent := Owner as TWinControl;
if Assigned(FHalloButton) then
Exit;
if csDesigning in ComponentState then begin
FHalloButton := TToolButton.Create(Parent);
FHalloButton.Parent := Self;
FHalloButton.FreeNotification(Self);
FHalloButton.Caption := 'Hallo';
end;
end;
destructor ZMyToolbart.Destroy;
begin
FHalloButton.Free;
inherited;
end;
procedure ZMyToolbart.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = FHalloButton) and (Operation = opRemove) then
FHalloButton := nil;
end;
initialization
RegisterClass(TToolButton);