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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…