当我将我的 iOS 设备设置为例如越南语时,以下代码有时会失败:
var
lFilePath: String
...
lFilePath := TPath.GetTempPath + '/MyDBfile.db';
lFileStream := TFileStream.Create(lFilePath, fmOpenReadWrite or fmShareExclusive or fmCreate);
TFileStream.Create 调用引发断言:“EFCreateError: Cannot create file "/private/var/mobile/Containers/Data/Application/{containerID}/tmp/MyDBfile.db" No such file or directory"。只有当设备设置为某些语言(包括越南语)时,才不会使用西欧语言提出断言。
我将创建代码跟踪到FileCreate
函数的这一行System.SysUtils
:
FileHandle := Integer(__open(M.AsAnsi(FileName, CP_UTF8).ToPointer,
O_RDWR or O_CREAT or O_TRUNC or Exclusive[(Mode and $0004) shr 2], Rights));
当提出断言时,FileHandle 为 -1。
有什么问题?
PS:在我试图找出发生了什么时,我添加了一个Fileexists
电话:
lFilePath := TPath.GetTempPath + '/MyDBfile.db';
if Fileexists(lFilePath) then
System.Sysutils.DeleteFile(lFilePath);
lFileStream := TFileStream.Create(lFilePath, fmOpenReadWrite or fmShareExclusive or fmCreate);
现在,在代码失败的情况下,我有以下奇怪的发现:在XCode中,它可以显示App的Container,它显示tmp/MyDBfile.db
Container中的文件,即文件确实存在(该文件仅由引用的代码,因此它是在代码成功的时间之一创建的)。但是,同时Fileexists
返回false。
该文件是一个 SQLite 文件,稍后sqlite3_open_v2
由sqlite3_close
. SQLite 是否可以将文件置于 Fileexists 返回 false 的状态?(重启应用后状态依然存在)