public { Public declarations } procedure SetIniFile(Strtitle, StrName :String;FileName : String); function ReadIniFile(Strtitle, StrName :String): String; function TForm11.ReadIniFile(Strtitle, StrName: String): String; var iniFile : TIniFile; begin iniFile := TIniFile.Create(ExtractFileDir(Application.ExeName)+'\Config.ini'); Result := iniFile.ReadString(Strtitle,StrName,''); IniFile.Free; end; procedure TForm11.SetIniFile(Strtitle, StrName :String; FileName: String); var iniFile : TIniFile; begin iniFile := TIniFile.Create(ExtractFileDir(Application.ExeName)+'\Config.ini'); showmessage(ExtractFileDir(Application.ExeName)); iniFile.WriteString(Strtitle,StrName,fileName); IniFile.Free; end; //写入 procedure TForm11.Button1Click(Sender: TObject); begin if FontDialog1.Execute then label1.Font := FontDialog1.Font; SetIniFile('title','font-size',inttostr(fontDialog1.Font.Size)); SetIniFile('title','font-color',inttostr(fontDialog1.Font.Color)); // fsBold, fsItalic, fsUnderline, fsStrikeOut if (fsBold in FontDialog1.Font.Style) then SetIniFile('title','font-style','fsBold'); if (fsItalic in FontDialog1.Font.Style) then SetIniFile('title','font-style','fsItalic'); if (fsUnderline in FontDialog1.Font.Style) then SetIniFile('title','font-style','fsUnderline'); if (fsStrikeOut in FontDialog1.Font.Style) then SetIniFile('title','font-style','fsStrikeOut'); SetIniFile('title','font-name',Fontdialog1.Font.Name); end; //读取 procedure TForm11.Button2Click(Sender: TObject); var titlefontstyle : TFontStyles; titlestyle : String; begin titlestyle := ReadIniFile('title','font-style'); if pos ('fsBold', titlestyle) > 0 then titlefontstyle := titlefontstyle + [fsBold]; if pos ('fsItalic', titlestyle ) > 0 then titlefontstyle := titlefontstyle + [fsItalic]; if pos ('fsUnderline' , titlestyle) > 0 then titlefontstyle := titlefontstyle + [fsUnderline]; if pos ('fsStrikeOut',titlestyle) >0 then titlefontstyle := titlefontstyle + [fsStrikeOut]; label1.Font.Style := titlefontstyle; label1.Font.Size := strtoint(ReadIniFile('title','font-size')); end;
标签:FontDialog,font,String,SetIniFile,title,delphi,ini,titlefontstyle,Font From: https://www.cnblogs.com/Thenext/p/17241714.html