使用ReWrite在Delphi 7中进行文件访问错误编程(f)
问题描述:
花了2个小时看着类似的问题,并使用了IsFileInUse,并且确定它已被使用。它使用MapObjectsLt加载一个jpg图像,虽然我确实了解一些文件锁定,但是这个软件在我们使用的Windows 7下运行得很完美。现在我已经转移到新的笔记本电脑上的Windows 10,它现在只出现一个错误。我自己和Windows资源管理器是我知道的唯一用户,因此没有其他人拥有打开时定位图像的小文本文件。我认为区别在于Windows。我使用ProcExp.exe来查看可能锁定/使用该文件的进程,并且找不到那个小的6行文件。我更改了我的代码,并在更改jgw/text文件之前卸载了该图像,之后重新加载并重新定位。如果MapObjectsLt锁定文件并且Windows 7允许更改?我是否会以某种方式更改代码,即强制删除一个句柄,知道没有人使用该文件?使用ReWrite在Delphi 7中进行文件访问错误编程(f)
procedure SaveWorldFile(FileName:TFileName);
var f:TextFile; i:Integer; Ext:String[4]; ImageFile:TFileName;
begin
ImageFile:=FileName;
if Pos('.SID',UpperCase(FileName))<>0 then Ext:='.sdw' else
if Pos('.JPG',UpperCase(FileName))<>0 then Ext:='.jgw' else Ext:='.tfw';
FileName:=ChangeFileExt(FileName,Ext);
//tried to close the handle in this function..because
//I believe at this point I am the only one using this file.
//Did not work but was part of my hunt for a solution
//I used for a different reason but found on this site
IsFileInUse(FileName);
//This section worked before and last line reloads the image
//The image is "untouched" only its position changes
//This worked under Windows 7 now Windows 10 does not
AssignFile(f,FileName);
ReWrite(f); //error under Windows 10
for i:=1 to 6 do WriteLn(f,P[i]:0:8);
CloseFile(f);
//Now reload the image
frmWRM.AddImageLayer(ImageFile);
end;
答
我发现您的网站上的解决方案,几小时后,我认为是Windows 10的错误。这是将文件复制到硬盘上的权限。一旦改变我的软件正常工作。感谢您的网站提示。
欢迎来到Stack Overflow!请更简洁地描述您的问题,以便其他人可以理解您已经做了什么以及您的问题是什么。请参阅https://stackoverflow.com/help/how-to-ask了解如何改善您的问题。 –
它会帮助你,如果你会发布代码和例外,你会得到 – GuidoG