Board index » cppbuilder » TFont property

TFont property


2006-03-24 01:34:12 PM
cppbuilder104
How can I set the default properties for a font object? My component has
three font properties and I would like to be able to set defaults for
the size, color, style, and typeface of the font.
 
 

Re:TFont property

"Joshua E Vines" < XXXX@XXXXX.COM >wrote in message
Quote
My component has three font properties and I would like
to be able to set defaults for the size, color, style, and
typeface of the font.
Just set them like any other property values, ie:
__fastcall TMyComponent::TMyComponent(TComponent *Owner)
: TComponent(Owner)
{
//...
FFont1 = new TFont;
FFont1->Size = 12;
FFont1->Color = clRed;
FFont1->Style = TFontStyles() << fsBold;
FFont1->Name = "Courier New";
// do the same for the other Font objects ...
}
Gambit
 

Re:TFont property

I understand how to set the properties. I am talking about the property
defaults as in "__property Font = {default=propertydefault};"
Remy Lebeau (TeamB) wrote:
Quote
"Joshua E Vines" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>My component has three font properties and I would like
>to be able to set defaults for the size, color, style, and
>typeface of the font.


Just set them like any other property values, ie:

__fastcall TMyComponent::TMyComponent(TComponent *Owner)
: TComponent(Owner)
{
//...
FFont1 = new TFont;
FFont1->Size = 12;
FFont1->Color = clRed;
FFont1->Style = TFontStyles() << fsBold;
FFont1->Name = "Courier New";

// do the same for the other Font objects ...
}



Gambit


 

{smallsort}

Re:TFont property

"Joshua E Vines" < XXXX@XXXXX.COM >wrote in message
Quote
I understand how to set the properties. I am talking about the
property defaults as in "__property Font = {default=propertydefault};"
You cannot apply a 'default' clause to a class-based property. The
'default' clause only works for POD values (numbers, bools, enums, etc).
If you really want to specify new default, then you have to derive a new
class from TFont, apply the defaults to the properties of that class, and
then use that class in your main component instead of TFont directly. For
example:
class TMyFont : public TFont
{
public:
__fastcall TMyFont();
__published:
__property Size = {default=12};
__property Color = {default=clRed};
};
__fastcall TMyFont::TMyFont()
: TFont()
{
Size = 12;
Color = clRed;
Style = TFontStyles() << fsBold; // cannot specify a default for a
Set
Name = "Courier New"; // cannot specify a default for a String
}
__fastcall TMyComponent::TMyComponent(TComponent *Owner)
: TComponent(Owner)
{
//...
FFont1 = new TMyFont;
// ...
}
Gambit