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 9255771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:47:06+00:00 2026-06-18T11:47:06+00:00

I would like to subclass TToolBar with another class called MyTToolBar so that I

  • 0

I would like to subclass TToolBar with another class called MyTToolBar so that I can override a method. I’m new to Delphi, but after two hours of trying various methods, I can’t get MyTToolBar to be used instead of TToolBar. I can’t be the first person who’s wanted to override a method on a visual component class.

I come more from an Xcode background where subclassing a visual component is easy. You create a subclass (e.g., MySubclass) of a parent class (e.g., MySuperClass) and then just simply assign the subclass in the Interface Builder view of Xcode. The subclass is automatically recognized and used.

Why can’t I seem to do this in Delphi RAD Studio XE3?

After adding a TToolBar to a TForm, it doesn’t seem possible to change the class. I tried through the Object Inspector as well as through the .PAS source code file. If I change the class in the .PAS file, I get an error message saying the toolbar “should be of type Vcl.ComCtrls.TToolBar but is declared as MyTToolbar. Correct the declaration?” This just seems silly…

Oh, and I’ve also used the new component wizard from selecting: File -> New -> Other -> Delphi Projects -> Delphi Files -> Component. I select the ancestor for MyTToolBar as TToolBar and tell it to register in the ‘Samples’ palette page. However, it doesn’t appear in the ‘Samples’ page.

  • 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-06-18T11:47:07+00:00Added an answer on June 18, 2026 at 11:47 am

    The closest equivilent to your XCode approach is to use an “interposer” class in Delphi. Basically, you do not change the code that the IDE creates for the standard TToolBar usage. You instead declare a new class that derives from the standard TToolBar component but is also named TToolBar and you make it visible to the compiler after the standard TToolBar has been declared. Whichever TToolBar class is last seen by the compiler will be the actual class type that gets instantiated whenever the TForm DFM is streamed.

    You can make your custom TToolBar class be seen by the compiler after the standard TToolBar class by one of two different ways:

    1. declare the custom TToolBar class in the same unit as your TForm class:

      unit MyForm;
      
      interface
      
      uses
        ..., Vcl.ComCtrls, ...;
      
      type
        TToolBar = class(Vcl.ComCtrls.TToolBar)
          // override what you need...
        end;
      
        TMyForm = class(TForm)
          ToolBar1: TToolBar; // <-- do not change this!
          ...
        end;
      
      implementation
      
      // implement custom TToolBar as needed...
      
      // normal TForm implementation code as needed ...
      
      end.
      
    2. you can declare the custom TToolBar class in its own unit that is then added to the TForm unit’s uses clause after the ComCtrls unit has been added:

      unit MyToolBar;
      
      interface
      
      uses
        ..., Vcl.ComCtrls;
      
      type
        TToolBar = class(Vcl.ComCtrls.TToolBar)
          // override what you need...
        end;
      
      implementation
      
      // implement custom TToolBar as needed...
      
      end.
      

      .

      unit MyForm;
      
      interface
      
      uses
        ..., Vcl.ComCtrls, ..., MyToolBar;
      
      type
        TMyForm = class(TForm)
          ToolBar1: TToolBar; // <- do not change this!
          ...
        end;
      
      implementation
      
      // normal TForm implementation code as needed ...
      
      end.
      

    This approach works on a per-project basis only. If you want to use your custom TToolBar class in multiple projects, then you are better off installing it into the IDE, like @KenWhite describes, and use it instead of the standard TToolBar. Go back to naming it TMyToolBar (or whatever), do not name it TToolBar anymore since it is not going to be used as an interposer. Make sure the Package is marked as “Runtime and Designtime” in its Project Options (creating separate runtime-only and designtime-ony Packages is outside the scope of this discussion). TMyToolBar will be available at design-time for you to drop on your TForm like any other component. If it is not, then you did not set it up correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how can I override indexOf() method in a subclass
I have a class that is a subclass of QObject that I would like
I would like to have my abstract parent class have a method that would
I would like to override Item`s find_items method in UserItem subclass. Should I add
I would like to override a generic function in a subclass, as follows: Superclass:
I have a custom subclass of NSSearchField that I would like to set the
In a method on an Ember.View subclass, I would like to make changes to
How can I code a custom init for NSManagedObject subclass? I would like something
I would like to know if I can add methods to a subclass of
I would like to create a subclass of UIActionSheet that uses blocks instead of

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.