Solved

Font property to INI file

Posted on 1998-11-03
2
1,031 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 58
Run video youtube webbrowse 10 45
Working with hours 3 31
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 18
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now