Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With FireMonkey and its cross-platforms, where should I store my application data?

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;
like image 291
Whiler Avatar asked Sep 15 '11 15:09

Whiler


1 Answers

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.

like image 173
Linas Avatar answered Nov 04 '22 20:11

Linas