【问题标题】:Save a TiniFile from application to iOS将 TiniFile 从应用程序保存到 iOS
【发布时间】:2013-10-22 11:39:04
【问题描述】:

我对 iOS 平台非常陌生。我正在尝试为我的应用程序保存一个 INI 文件。问题是我无法获得具有写权限的路径。

这是我的代码:

  ini := TIniFile.Create(GetHomePath + '/user.dat');
  try
    ini.WriteString('data','user',edtuser.Text);
    ini.WriteString('data','descr',edt1.Text);
  finally
    ini.Free;
  end;

我收到无法创建文件的异常。如何使用 Firemonkey 获得可写路径?

【问题讨论】:

    标签: ios delphi firemonkey delphi-xe5


    【解决方案1】:

    使用TPath.GetDocumentsPath(并使用TPath.Combine而不是连接,以删除硬编码的/):

    uses
      System.IOUtils;
    
    
    ini := TIniFile.Create(TPath.Combine(TPath.GetDocumentsPath, 'user.dat'));
    

    使用TPath.GetDocumentsPath 透明地适用于所有支持的平台(Win32、Win64、OSX、iOS 和 Android),使用TPath.Combine 将自动添加TPath.DirectorySeparatorChar,因此您不必手动连接它们。

    如果您更喜欢自己做:

    var
      IniName: string;
    begin
      IniName := TPath.GetDocumentsPath + TPath.DirectorySeparatorChar + 'user.dat';
      Ini := TIniFile.Create(IniName);
      try
        // Rest of code
      finally
        Ini.Free;
      end;
    end;
      
    

    【讨论】:

      【解决方案2】:

      可能是thisthis 可以帮助你

      uses INIFiles;
      
      function TForm6.MyINIFilePath: string;
      begin
      //  Result := GetHomePath + PathDelim + 'Library' + PathDelim+'My.ini';
        Result := GetHomePath + PathDelim + 'Documents' + PathDelim+'MyD.ini';
      end; 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-12
        • 1970-01-01
        • 2021-03-14
        相关资源
        最近更新 更多