Solved

Font property to INI file

Posted on 1998-11-03
2
1,038 Views
Last Modified: 2013-12-02
I am trying to save some component's Font property ini INI file:

with Memo1 do
begin
      IniFile.WriteString('Font desc', 'Name', Font.Name);
      IniFile.WriteInteger('Font desc', 'Color', Font.Color);
      IniFile.WriteInteger('Font desc', 'Size', Font.Size);
      IniFile.WriteInteger('Font desc', 'Style', Font.Style);
end;

but it fails at compiling last line, since Style is defined as

TFontStyle = (fsBold, fsItalic, fsUnderline, fsStrikeOut);
TFontStyles = set of TFontStyle;
property Style: TFontStyles;



Same with loading from INI

with Memo1 do
begin
      Font.Name := IniFile.ReadString('Font desc', 'Name', 'Arial');
      Font.Color := IniFile.ReadInteger('Font desc', 'Color', clBlack);
      Font.Size := IniFile.ReadInteger('Font desc', 'Size', 8);
      Font.Style := IniFile.ReadInteger('Font desc', 'Style', fsBold));
end;


How to save value of set variables (like Style) in INI
(apart from creating separate boolean key for every member of set)


0
Comment
Question by:yuhoo
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 50 total points
ID: 1345507
TFontStyle is an ordinal type.  You can convert it to an integer using the ord function.

IniFile.WriteInteger('Font desc', 'Style', ord(Font.Style));

When you read it in:

x := IniFile.ReadInteger('Font desc', 'Style', 0));
Font.Style := TFontStyle(x);

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1345508
I just realized that you want to store TFontStyles rather than TFontStyle.

Instead of using ord, you use a typecast.  A set is stored in a byte, so you can typecast it to a byte.

var x :longint;  

{to write}

x := Byte(Font.Style);
IniFile.WriteInteger('Font desc', 'Style', x);

{to read}
 
x := IniFile.ReadInteger('Font desc', 'Style', 0));
Font.Style := TFontStyles(Byte(x));


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 110
Google Chrome color inconsistency 2 70
How are Button Fonts Created? 2 31
firemonkey Android Listview Sort items 7 49
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question