I get an I/O Error 1784 due to blockwrite in the following code which overwrites 3 times a file.
I presume I/O Error 1784 means ERROR_INVALID_USER_BUFFER.
I don't know why. The error appears sometimes, not at each run...
Could you help me ?
procedure overwrite_files_3_times(iPath : string);
var
numwritten : integer;
iFileSize, iPosition : int64;
InFile : File of byte;
ipBufBlock : pTBUFFER;
k : integer;
begin
if not FileExists(iPath) then
exit;
FileMode := fmOpenRead or fmOpenWrite or fmShareDenyNone;
AssignFile(InFile, iPath);
Reset(InFile);
iFileSize := getfilesize2(iPath); // retrieve the filesize
iPosition := 0;
// 3 overwrites
for k:= 0 to 3-1 do
begin
Seek(InFile, 0);
iPosition := 0;
///////////////////
// on écrit
while iPosition + sizeOf(TBuffer) < iFileSize do
begin
BlockWrite(InFile,ipBufBlock^,sizeOf(TBuffer),numwritten);
iPosition := iPosition + sizeOf(TBuffer);
end;
// the end
if iPosition <= iFileSize -1 then
begin
BlockWrite(InFile,ipBufBlock^,iFileSize-iPosition,numwritten); //-->> generate I/O Error 1784
end;
end;
////////////////
CloseFile(InFile);
end;