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.