在网上找到一种方法,但不知道怎样保存到INI文件。方法如下:
想将font.style保存到ini和从ini中读取,由于tfontstyles是个集合,不好保存.
下面是解决方法(已测试,我正在使用 :o)  呵呵 
const 
   fontstylevalue: array [tfontstyle] of dword = ($0001, $0002, $0004, $0008);
function fontstyletodword(fontstyles: tfontstyles): dword;
var
  fontstyle: tfontstyle;
begin
  result := 0;
  for fontstyle := low(tfontstyle) to high(tfontstyle) do
  begin
    if fontstyle in fontstyles then
      inc(result, fontstylevalue[fontstyle]);
  end;
end;
function dwordtofontstyle(value: dword): tfontstyles;
var
  fontstyle: tfontstyle;
begin
  result := [];
  for fontstyle := low(tfontstyle) to high(tfontstyle) do
  begin
    if (fontstylevalue[fontstyle] and value) = fontstylevalue[fontstyle] then
      result := result + [fontstyle];
  end;
end;
高送分100.

解决方案 »

  1.   

    可以直接通过流保存到文件,不用ini
      

  2.   

    全部用字符串存储,格式如下
    [Font]
    Charest = DEFAULT_CHARSET
    Color = clRed
    ...读取字体信息可以根据它相对应的信息转换格式就OK了。
      

  3.   

    给你两个函数。
    //保存字体
    function SaveFont(MidFont:TFont;FileName,CtrName:String):Boolean;
    var
        FontFile:TIniFile;
    begin
      Result:=True;
      FontFile:=TIniFile.Create(FileName);
      FontFile.WriteString(CtrName, 'FontName', MidFont.Name);
      FontFile.WriteString(CtrName, 'FontStyle',SetFontStyle(MidFont.Style));
      FontFile.WriteInteger(CtrName, 'FontCharSet', MidFont.CharSet);
      FontFile.WriteInteger(CtrName, 'FontColor', MidFont.Color);
      FontFile.WriteInteger(CtrName, 'FontSize', MidFont.Size );
      FontFile.WriteInteger(CtrName, 'FontHeight',MidFont.Height);
      FontFile.Free;
    end;//加载字体
    function LoadFont(FileName,CtrName:String;var MidFont:TFont):Boolean;
    var
        FontFile:TIniFile;
    begin
      Result:=True;
      FontFile:=TIniFile.Create(FileName);
      MidFont.Name:=FontFile.ReadString(CtrName,'FontName','宋体');
      MidFont.Style:=GetFontStyle(FontFile.ReadString(CtrName,'FontStyle','[]'));
      MidFont.CharSet:=FontFile.ReadInteger(CtrName,'FontCharSet',134);
      MidFont.Color:=FontFile.ReadInteger(CtrName,'FontColor',-2147483640);
      MidFont.Size:=FontFile.ReadInteger(CtrName,'FontSize',9);
      MidFont.Height:=FontFile.ReadInteger(CtrName,'FontHeight',-12);
      FontFile.Free;
    end;
      

  4.   

    uses inifiles
    写到INI文件里面。
      

  5.   

    FontFile.WriteString(CtrName, 'FontStyle',SetFontStyle(MidFont.Style));这个SetFontStyle()哪来的
      

  6.   

    不好意思。function GetFontStyle(sStyle: string): TFontStyles;
    //»ñµÃ×ÖÌåÑùʽ
    //sStyle : ×ÖÌå×Ö·û´®ÐÎʽ
    //·µ»Ø   : ×ÖÌå¸ñʽvar
      MyFS              : TFontStyles;
    begin
      MyFS := [];
      if pos('fsBold', sStyle) > 0 then MyFS := MyFS + [fsBold];
      if Pos('fsItalic', sStyle) > 0 then MyFS := MyFS + [fsItalic];
      if Pos('fsUnderline', sStyle) > 0 then
        MyFS := MyFS + [fsUnderline];
      if Pos('fsStrikeOut', sStyle) > 0 then
        MyFS := MyFS + [fsStrikeOut];
      Result := MyFS;
    end;function SetFontStyle(FS: TFontStyles): string;
    //»ñµÃ×ÖÌåÑùʽµÄ×Ö·û´®ÐÎʽ
    //FS   : ×ÖÌå¸ñʽ
    //·µ»Ø : ×ÖÌå×Ö·û´®ÐÎʽvar
      Mystyle  : string;
    begin
      Mystyle := '[';
      if fsBold in FS then MyStyle := MyStyle + 'fsBold';
      if fsItalic in FS then
        if MyStyle = '[' then
          MyStyle := MyStyle + 'fsItalic'
        else
          MyStyle := MyStyle + ',fsItalic';
      if fsUnderline in FS then
        if MyStyle = '[' then
          MyStyle := MyStyle + 'fsUnderline'
        else
          MyStyle := MyStyle + ',fsUnderline';
      if fsStrikeOut in FS then
        if MyStyle = '[' then
          MyStyle := MyStyle + 'fsStrikeOut'
        else
          MyStyle := MyStyle + ',fsStrikeOut';
      MyStyle := MyStyle + ']';
      Result := MyStyle;
    end;
      

  7.   

    、、建议将FONT的name\size\color等属性分别保存即可。