Hi,
I have an application that basically copies a file's contents into a new file and then adds some text at the end of the new copied file.
The trouble is I get the message "Project DigSig.exe raised exception class EAccessViolation with message 'Access Violation at address 00403B22 in module 'DigSig.exe'. Read of addess 450A4647'. Process stopped. Use Step or Run to continue.".
I stepped through the code and the exception is thrown when I try and close the copied file i.e.
CloseFile(g);
I just can't work out why this is happening as the same code runs fine in another project. Any help would be much appreciated. Here is a sample of the code:
try
new_filename := 'C:\temp\temp.pdf';
AssignFile(f, filename);
AssignFile(g, new_FileName);
try
Reset(f, 1); { Record size = 1 }
//Reset(g, 1); { Record size = 1 }
Rewrite(g, 1); { Record size = 1 }
//
// Create a copy of the file
//
repeat
BlockRead(f, Buf, SizeOf(Buf), NumRead);
BlockWrite(g, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
//
// Add stuff to end of file
//
finally
CloseFile(f);
CloseFile(g); // causes exception to be raised
end;
I have an application that basically copies a file's contents into a new file and then adds some text at the end of the new copied file.
The trouble is I get the message "Project DigSig.exe raised exception class EAccessViolation with message 'Access Violation at address 00403B22 in module 'DigSig.exe'. Read of addess 450A4647'. Process stopped. Use Step or Run to continue.".
I stepped through the code and the exception is thrown when I try and close the copied file i.e.
CloseFile(g);
I just can't work out why this is happening as the same code runs fine in another project. Any help would be much appreciated. Here is a sample of the code:
try
new_filename := 'C:\temp\temp.pdf';
AssignFile(f, filename);
AssignFile(g, new_FileName);
try
Reset(f, 1); { Record size = 1 }
//Reset(g, 1); { Record size = 1 }
Rewrite(g, 1); { Record size = 1 }
//
// Create a copy of the file
//
repeat
BlockRead(f, Buf, SizeOf(Buf), NumRead);
BlockWrite(g, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
//
// Add stuff to end of file
//
finally
CloseFile(f);
CloseFile(g); // causes exception to be raised
end;