Hello everyone,
Reading this post I note two areas where I can add my own opinion and (if possible) my programmer's experience.
First, when using the Assign(...) and Reset(....) procedures, one should prevent program crashes when the expected file is not there or any I/O error occurs.
In TurboPascal and Delphi this is achieved using the compiler directive {$I ±} like this:
AssignFile( ff, my_file_name ); // AssignFile) is the Delphi equiv of Assign(
{$I-} Reset(ff), {$I+} // {$I-} turns off the I/O error reporting
ErrorCode := IOResult; // IOResult is a function reporting the status of the I/O
if ErrorCode > 0 then ... report an error here according
Similarily one should use this compiler directive with the Close() procedure (in case the file haden't been opened because of an error, this would prevent a second error)
Second, if FileExists( does not exist in Free pascal, find if a similar compiler directive to $I in FreePascal and use the following small function....
function FileExists( filename: String): boolean;
var ff : TextFile; // or : Text
begin
Result := False; // Early leaves are concidered as file doesn't exist
AssignFile( ff, filename );
{$I-} Reset(ff); {$I+}
if IOResult > 0 then Exit; // Some I/O error occured - leave function
// If we get here, the file opened successfully so we have to close-it
Result := True;
{$I-} CloseFile(ff); {$I+} // or Close(ff)
end; // FileExists
Marcel