BCB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BCB] Re:



Torrin,
    Tried that myself once, and I believe that's the wrong approach to take
at it.  The TFontSyle property is a Set, and the Data field within Set that
holds the various items in a unsigned char array (see sysdefs.h approx line
671) and cannot be represented by an integer without some sort of
conversion.  If Set held the data as an integer value (like TBrush does with
its style), then you could probably get away with doing that, but that would
make 4 squared plus 1 (17) possibilities to chose from when choosing a font
style.  If Set were bitwise, then fsBold (as it currently is) would never be
held because fsBold actually has a enumerated value of 0 (see graphics.hpp
approx. line 22).  So when Style's Set is empty, the font style is normal,
but when Style's Set contains a value of 0 within its Data property, then
fsBold is turned on.
    Here's how to get around the problem:  I have two methods that do the
conversion for me called EncodeFontStyle and ApplyEncodedFontStyle and use
them regularly when saving a style to the registry.  I have encluded them
below.  I hope that this helps.
Sincerely,
Eric Bewley
Commercial Real Estate Systems,
Bank One of Arizona
ebewley@nospam.bigfoot.com

//---------------------------------------------------------------------------

const int __fastcall EncodeFontStyle(TFont* Font)
{
  return  (Font->Style.Contains(fsBold) << 3) +
        (Font->Style.Contains(fsItalic) << 2) +
        (Font->Style.Contains(fsUnderline) << 1) +
        Font->Style.Contains(fsStrikeOut);
}

//---------------------------------------------------------------------------

void __fastcall ApplyEncodedFontStyle(TFont *Font, const int Style)
{
 Font->Style.Clear();
  if (Style & 8)
    Font->Style = Font->Style << fsBold;
  if (Style & 4)
    Font->Style = Font->Style  << fsItalic;
  if (Style & 2)
    Font->Style = Font->Style  << fsUnderline;
  if (Style & 1)
    Font->Style = Font->Style  << fsStrikeOut;
}
//---------------------------------------------------------------------------







Torrin Jones wrote:

> I tried the cast error away with int but the compiler gave me the
> same error.  Are there any other suggestions?  Is there a getstyle
> member function that I am missing somewhere?  Let's look.
>
> Here is the line that I used.
>
> RegKey->WriteInteger("Style", FontDialog1->Font->Style);
>
> And here is the error I get.
>
> [C++Error] Unit1.cpp(76): Cannot cast
> from 'System::Set<Graphics::TFontStyle,0,3>' to 'int'.
>
> TAJ



W Komornicki's Home Page | Main Index | Thread Index