FONT有很多属性啊,我想用INI文件控制FONT的所有属性,在打开和关闭窗体时,我想对FONT的SIZE,COLOR,STYLE等等属性分别控制写入和读出,我的INI文件应该如何写啊?是否写成:font.size=.....
font.color=......
.......还是只写一个font=.....就可以了???高手告诉我具体怎么写啊?先谢了

解决方案 »

  1.   

    当然是得个个写,首先你要看Font中各种属性是什么类型。
    如果是基本类型,则可以直接写入INI,比如Color,Size,这都是整形,可以直接写入
    而有些是枚举型的,比如Style,则不能直接写入,可以写个函数,将该枚举型直接映射成基本类型,再写入INI,读出来时再写一个函数,将该类型又映射回枚举类型。
      

  2.   

    //参考如下代码~~
    uses IniFiles, TypInfo;procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TIniFile.Create('c:\temp\temp.ini') do try
        Font.Name := ReadString(Self.ClassName, 'Font.Name', Font.Name);
        Font.Size := ReadInteger(Self.ClassName, 'Font.Size', Font.Size);
        Font.Color := ReadInteger(Self.ClassName, 'Font.Color', Font.Color);
        SetSetProp(Font, 'Style', ReadString(Self.ClassName, 'Font.Style',
          GetSetProp(Font, 'Style', True)));
      finally
        Free;
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      with TIniFile.Create('c:\temp\temp.ini') do try
        WriteString(Self.ClassName, 'Font.Name', Font.Name);
        WriteInteger(Self.ClassName, 'Font.Size', Font.Size);
        WriteInteger(Self.ClassName, 'Font.Color', Font.Color);
        WriteString(Self.ClassName, 'Font.Style',
          GetSetProp(Font, 'Style', True));
      finally
        Free;
      end;
    end;