如何读出TFont中的值,并将其保存为文本型,下次运行时读取!

解决方案 »

  1.   

    自定义一个记录类型,将TFont的各个属性保存在一个记录中。然后将记录保存在记录文件中,,下次Load这个文件.
      

  2.   

    建立一INI文件用来专门保存字体文件信息,如大小,颜色等。
      

  3.   

    非常感谢!我怎么将诸如TColor,TCharset类型值转化为string型呢?
      

  4.   

    你调用fontdialog
    if fontdialog.execute then
    font:=fontdialog.filename;//保存
    savefileto
      

  5.   

    var
       MyFile: file of Tfont;
       MyFont: TFont;
    beginend;
      

  6.   

    那就随便给你段代码吧:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,IniFiles;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}//save
    procedure TForm1.Button1Click(Sender: TObject);
    var
      IniFileName:String;
      MyIniFile:Tinifile;
      FFont:TFont;
    begin
      IniFileName:=ExpandFileName(ExtractFilePath(Application.ExeName)+'\SystemSet.ini');
      MyIniFile:=Tinifile.Create(inifilename);
      MyIniFile.WriteString('Font','FontName',FFont.Name);
      MyIniFile.WriteInteger('Font','FontSize',FFont.Size);
      //其它你自己加上;
    end;//load
    procedure TForm1.FormCreate(Sender: TObject);
    var
      IniFileName:String;
      MyIniFile:Tinifile;
    begin
      IniFileName:=ExpandFileName(ExtractFilePath(Application.ExeName)+'\SystemSet.ini');
      MyIniFile:=Tinifile.Create(inifilename);
      //下面就比如说你要把字体信息赋给Button;
      Button1.Font.Name:=MyIniFile.ReadString('Font','FontName','wrong');
      Button1.Font.Size:=MyIniFile.ReadInteger('Font','FontSize',0);
      //其它的自己加上;
    end;end.
      

  7.   

    TFont 本身就可以持久化,不需要另外多写代码