Setting a custom component's default caption.

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Setting a custom component's default caption.

Postby Jon » Wed Feb 16, 2005 5:17 pm

I'm creating a custom component and I would like to set the component's default caption to the component's name, just like standard components. I figured I'd just do this in the constructor:

Label->Caption = this->Name;

However, the Name has not yet been set in the constuctor, so this will not work. Same story during AfterConstruction; this->Name is null.

Ideas how I can simply set the default caption to the component's name?

Postby Damon » Fri Feb 18, 2005 11:27 pm

Hi Jon,
The Caption property should be set to the Name automatically, as long as the csSetCaption flag is present in the ControlStyle property (which it is by default for all TControl descendants). From which VCL class does your component descend? Check to see that csSetCaption is present in the ControlStyle property.

If all else fails, you can set the Caption manually from within an augmented SetName() method; for example...

class PACKAGE TMyLabel : public TGraphicControl
void __fastcall SetName(AnsiString const NewName);
__fastcall TMyLabel(TComponent* Owner);
__property Caption;

void __fastcall TMyLabel::SetName(AnsiString const NewName)
Caption = NewName;

Good luck,
User avatar
BCBJ Editor and Admin
BCBJ Editor and Admin
Posts: 285
Joined: Wed May 26, 2004 11:25 pm
Location: Stillwater, OK, USA

Postby Jon » Mon Feb 21, 2005 1:44 pm

My component is a decendant of TCustomControl, so I don't know why csSetCaption wasn't setting the caption automatically. As you suggested, I simply added a SetName () function which worked perfectly fine. Thanks


Return to Technical

Who is online

Users browsing this forum: Google [Bot] and 26 guests