我对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;我得到了一个异常,无法创建该文件。如何使用Fire猴子获得可写路径?
发布于 2013-10-22 13:10:57
使用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;发布于 2013-10-22 16:37:49
可能是这或这可以帮到你
uses INIFiles;
function TForm6.MyINIFilePath: string;
begin
// Result := GetHomePath + PathDelim + 'Library' + PathDelim+'My.ini';
Result := GetHomePath + PathDelim + 'Documents' + PathDelim+'MyD.ini';
end; https://stackoverflow.com/questions/19516804
复制相似问题