In Delphi implementation will font.style write INI file

Source: Internet
Author: User
Tags ini

Before long I wrote a small program in the INI file to record the font properties (color value/color, size/size, font name/name, style/style), where color and size values can be written to the INI file numerically, name is written in characters, But Font.style is not numeric, character, and not Boolean, but Tfontstyles class, can not directly write INI file to go, I find a lot of related books also did not find a way, also to the network on the Delphi site to ask, also did not get a satisfactory answer, can't, It seems to have to find a way to solve, I passed a series of groping experiments, finally found a more satisfactory solution, the program code is as follows:

1, first in the uses to join the Inifiles;

2. Define Variables

var
Mystyle : string;
Myini : inifile;
3、写
begin
Mystyle := [;
Myini := TInifile.Create (inifile.ini);
with FontDialog.Font do
begin
if fsBold in Style then MyStyle := MyStyle + fsBold;
if fsItalic in Style then
if MyStyle = [ then
MyStyle := MyStyle + fsItalic
else
MyStyle := MyStyle + ,fsItalic;
if fsUnderline in Style then
if MyStyle = [ then
MyStyle := MyStyle + fsUnderline
else
MyStyle := MyStyle + ,fsUnderline;
if fsStrikeOut in Style then
if MyStyle = [ then
MyStyle := MyStyle + fsStrikeOut
else
MyStyle := MyStyle + ,fsStrikeOut;
MyStyle := MyStyle + ];
end;
Myini.WriteString (FontStyle, style, MyStyle);
Myini.free;
End;

4. READ:

var
MyFontStyle : TFontStyles;
MyStyle : string;
begin
MyFontStyle := [];
Myini := TInifile.Create (inifile.ini);
Mystyle := Myini.ReadString (Fontstyle, style, []);
if pos (fsBold, Mystyle) $#@62; 0 then MyFontStyle := MyFontStyle + [fsBold];
if Pos (fsItalic, MyStyle) $#@62; 0 then MyFontStyle := MyFontStyle + [fsItalic];
if Pos (fsUnderline, MyStyle) $#@62; 0 then
MyFontStyle := MyFontStyle + [fsUnderline];
if (fsStrikeOut, MyStyle) $#@62; 0 then
MyFontStyle := MyFontStyle + [fsStrikeOut];
FontDialog.Font.Style := MyFontStyle;
MyIni.free;
end;

The above code runs through Delphi 4.0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.