Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4026800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:01:02+00:00 2026-05-20T11:01:02+00:00

I want to create a custom toolbar control (descendant TToolBar) which should have some

  • 0

I want to create a custom toolbar control (descendant TToolBar) which should have some default-toolbarButtons.

So I’ve created a simple constructor which creates 1 default button:

constructor ZMyToolbart.Create(AOwner: TComponent);
var
  ToolButton : TToolButton;
begin
  inherited;
  Parent := Owner as TWinControl;
  ToolButton := TToolButton.Create(Self);
  ToolButton.Parent := Self;
  ToolButton.Caption := 'Hallo';
end;

The problem is, after draggign the custom control on a form, the toolbar-button is visible, but it’s not shown in the object inspector as a part of the toolbar.

If tried to assign the button via the button property of the toolbar, but this doesn’t work.
Maybe somebody has an advice how this could be done? thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:01:03+00:00Added an answer on May 20, 2026 at 11:01 am

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom control in C#. But every time I have
I want to know if i can create a custom google maps application,on which
I want to create a custom MSBuild task that changes my .cs files before
If you want to create a custom attribute for MS test (say [Repeat(3)] how
In C# if I want to create a Custom Event you do something like
I want to create extra rules in FXCop. Custom Rules to help ensure specific
I want create a drop shadow around the canvas component in flex. Technically speaking
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the
I want to create a function that performs a function passed by parameter on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.