[Solved] Save custom font ?? lazarus / 21-General ---------------------------------------------------------------------- majid.ebru · 2022-02-13 06:18 Hi in my program , user can change font of memo(or other components). how can i save font properties to text file and read it again ? best regards ---------------------------------------------------------------------- dbannon · 2022-02-13 06:42 Its an application setting, save font name to a file and read it back at startup. FPC/Lazarus has support for complicated settings file using ini (my choice), xml and json at least. https://wiki.freepascal.org/Using_INI_Files https://wiki.freepascal.org/XML_Tutorial Each operating system has its own ideas about where settings files should be stored. Davo ---------------------------------------------------------------------- majid.ebru · 2022-02-13 06:55 Thank you now how can i save Fontstyle,colorfont , ....?? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin    ReadSettings;    ShowSettings;end; procedure TForm1.CheckBox1Change(Sender: TObject);begin    WriteSettings;    ShowSettings;end; procedure TForm1.ShowSettings;begin    Memo1.Clear;    Memo1.Append('X=' + memo1.font.style ???? );end; procedure TForm1.CheckBox1Change(Sender: TObject);begin    WriteSettings;    ShowSettings;end; ---------------------------------------------------------------------- dbannon · 2022-02-13 07:19 My app writes an INI file. I call it a cfg file incase the Linux users get offended. Totally untested code, cannot do more now, her Ladyship wishes to go out for tea. It has a block that includes - Code: [Select][BasicSettings] ... FontSize=12 UsualFont=Ubuntu FixedFont=Monospace Write like this ..... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.WriteConfigFile() : boolean;var        ConfigFile : TINIFile;begin    ConfigFile :=  TINIFile.Create('myapp.ini');    try        try            ConfigFile.writestring('BasicSettings', 'FontSize', inttostr(Memo1.Font.Size));            ConfigFile.writestring('BasicSettings', 'UsualFont', Memo1.Font.Name);        finally            ConfigFile.Free;        end;    except on E: Exception do begin            showmessage('Unable to write config to ' + LabelSettingPath.Caption);            Result := False;        end;    end;    // debugln('just wrote a settings file out');end;                   Hope this helps, the read is pretty much to reverse, the wiki page has details. Davo ---------------------------------------------------------------------- majid.ebru · 2022-02-13 07:26 my big problem is , save Fontstyle and Effects . i can't save these properties ?!?!?! i should save (wite to file) and read these properties ?!?! Thank you ---------------------------------------------------------------------- dseligo · 2022-02-13 07:38 This works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses IniFiles; const IniFile = 'settings.ini'; procedure TForm1.Button1Click(Sender: TObject);var Sett: TIniFile;begin  Sett := TIniFile.Create(IniFile);  try    Sett.WriteInteger('Font', 'Style', Integer(Memo1.Font.Style));    Sett.WriteInteger('Font', 'Color', Memo1.Font.Color);    Sett.WriteString('Font', 'Name', Memo1.Font.Name);  finally    Sett.Free;  end;end; procedure TForm1.FormCreate(Sender: TObject);var Sett: TIniFile;begin  If FileExists(IniFile) then  begin    Sett := TIniFile.Create(IniFile);  try      Memo1.Font.Style := TFontStyles(Sett.ReadInteger('Font', 'Style', 0));      Memo1.Font.Color := Sett.ReadInteger('Font', 'Color', 0);      Memo1.Font.Name := Sett.ReadString('Font', 'Name', 'default');    finally      Sett.Free;    end;  end;end; ---------------------------------------------------------------------- majid.ebru · 2022-02-13 08:34 Thank you ---------------------------------------------------------------------- Jorg3000 · 2022-02-13 09:44 Hi! I have an addition to it: E.g. on Windows you can't write to the "Program Files" folder, so you can't save a user-modifiable .ini file there. I don't know how it is on Linux/MacOS, but in general I would recommend writing the .ini file to the AppConfig folder. You can get it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IniPath := GetAppConfigDir(false); Regards, Jörg ---------------------------------------------------------------------- trev · 2022-02-13 11:22 For where to store INI files in macOS, see the Wiki artcile: Locating macOS app support, preferences folders. ---------------------------------------------------------------------- jcmontherock · 2022-02-13 16:20 You can also see the Remy's post at: https://forum.lazarus.freepascal.org/index.php?topic=36128.0