he DeleteFile function deletes an existing file. BOOL DeleteFile( LPCTSTR lpFileName // pointer to name of file to delete ); ParameterslpFileNamePoints to a null-terminated string that specifies the file to be deleted. Return ValuesIf the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. ResIf an application attempts to delete a file that does not exist, the DeleteFile function fails. Windows 95: The DeleteFile function deletes a file even if it is open for normal I/O or as a memory-mapped file. To prevent loss of data, close files before attempting to delete them. Windows NT: The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file. To close an open file, use the CloseHandle function.
);
ParameterslpFileNamePoints to a null-terminated string that specifies the file to be deleted. Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. ResIf an application attempts to delete a file that does not exist, the DeleteFile function fails.
Windows 95: The DeleteFile function deletes a file even if it is open for normal I/O or as a memory-mapped file. To prevent loss of data, close files before attempting to delete them.
Windows NT: The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.
To close an open file, use the CloseHandle function.
可是我的文件这样保存和删除的
DeleteFile(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'); //
tblobfield(dmcell.qryCELLTABLE.fieldbyname('content')).SaveToFile(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'); 文件经常说受到保护无法删除,文件名是trim(dmcell.qryCELLTABLE.fieldbyname('bid').value),我不能将dmcell.qryCELLTABLE close,所以还是有问题
fs.free;
FS:TFileStream; DeleteFile(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'); //FS:=TFileStream.create(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll',fmcreate);//fscreate参数不知道是否正确 tblobfield(dmcell.qryCELLTABLE.fieldbyname('content')).SaveToFile(fs);
fs.free;
第一
dir:=getcurrentdir+'\db';
createdirectory('db',nil);
Windows.DeleteFile(pchar(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'));
tblobfield(dmcell.qryCELLTABLE.fieldbyname('content')).SaveToFile(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll');
cell1.OpenFile(dir+'\'+dmcell.qryCELLTABLE.fieldbyname('bid').value+'.cll', '');第二
temp:=TBlobStream.Create(TBlobField(dmcell.qryCELLTABLE.fieldbyname('content')),bmRead);
MStream:=TMemoryStream.Create;
MStream.LoadFromStream(temp);
MStream.SaveToFile(dir+'\'+dmcell.qryCELLTABLE.fieldbyname('bid').value+'.cll');
MStream.free;
cell1.OpenFile(dir+'\'+dmcell.qryCELLTABLE.fieldbyname('bid').value+'.cll', '');
Windows.DeleteFile(pchar(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'));
FS:=TFileStream.create(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll',fmcreate);//fscreate参数不知道是否正确
tblobfield(dmcell.qryCELLTABLE.fieldbyname('content')).SaveTostream(fs);
fs.free;第二 Windows.DeleteFile(pchar(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'));
temp:=TBlobStream.Create(TBlobField(dmcell.qryCELLTABLE.fieldbyname('content')),bmRead);
MStream:=TMemoryStream.Create;
MStream.LoadFromStream(temp);
MStream.SaveToFile(dir+'\'+dmcell.qryCELLTABLE.fieldbyname('bid').value+'.cll');
MStream.free;第三
Windows.DeleteFile(pchar(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll'));
tblobfield(dmcell.qryCELLTABLE.fieldbyname('content')).SaveToFile(dir+'\'+trim(dmcell.qryCELLTABLE.fieldbyname('bid').value)+'.cll');
全部是文件被保护无法删除。
Windows.DeleteFile通过不报警,但跟踪在此时文件还存在,如果手工删则报文件处于保护