Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert TFontStyles to an integer?

Status
Not open for further replies.

TimSNL

Programmer
Sep 11, 2001
119
AU
Hello everyone.

I need to save some TFontStyles values to my database and thought the best way would be to convert this set datatype into an integer. I have found that this is harder to do than I thought. Any help please?

Thanks,
Tim
 
Use this code:

Code:
var
  Mask      : integer;
  Style     : TFontStyle;   
  i         : integer;
  StyleSet  : TFontStyles;
begin
  // Set to integer <<<<<<<<<<
  // Translate the set into a bit mask 
  Mask := 0;
  for Style := Low(TFontStyle) to High(TFontStyle) do
    if Style in Font.Style
      then Mask := Mask or (1 shl Ord(Style));
  MessageBox(0, PChar((IntToStr(Mask))), 'MASK', 0);
  // Integer to set <<<<<<<<<<
  // Translate the bit mask into a set
 StyleSet := [];
 for i := 0 to Ord(High(TFontStyle)) do
  if Mask and (1 shl i) <> 0
    then StyleSet := StyleSet + [TFontStyle(i)];
 // Back check
 if Font.Style = StyleSet
  then MessageBox(0, 'Sets are equal', 'Check', 0)
  else MessageBox(0, 'Sets are different', 'Check', 0);
end;

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top