Usually, with Windows, I save my application's data in the user folder (%appdata%).
For that, I use the function ExpandEnvironmentStrings
which is linked to Windows to get the folder I need, and I store inside a subfolder my inifile.
Is there any best practice to manage that and be compliant with all the supported platforms (Windows 32b, 64b & Mac)?
I successfully tested like that:
procedure TfrmMain.SaveSettings;
var
fnINI: TFileName;
ini : TIniFile;
begin
fnINI := IncludeTrailingPathDelimiter(GetHomePath) + IncludeTrailingPathDelimiter(APP_NAME) + ChangeFileExt(APP_NAME, '.ini');
if ForceDirectories(ExtractFilePath(fnINI)) then
begin
ini := TIniFile.Create(fnINI);
try
ini.WriteString(INI_CONNECTION, INI_IP, edtIP.Text);
finally
ini.Free;
end;
end;
end;
Haven't tried XE2 but probably you could use SysUtils.GetHomePath. Also check IOUtils
where you can find useful records (TFile, TPath, TDirectory) for managing files, paths and directories. They should support different platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With