Discussion:
Trouble with file handling
(too old to reply)
c***@gmail.com
2008-12-28 15:01:43 UTC
Permalink
Hi All,
It is not easy to find programming manual for Pascal on the
internet.
I am trying to open a file to read, and detect if there is an error
in file operations, for example 'file does not exist'.
The following code was taken from freepascal's manual, however it
does not work:

fn := paramstr (1);
Assign (source, fn); Reset (source);
if IOResult<>0 then
begin writeln ('File ', fn,' doesn't exist.'); halt; end;

As the program attempts to read a file that does not exist, runtime
error occurs:
Runtime error 2 at $08066E68
$08066E68
$0805E7B4
$0806D681

I am currently using freepascal.

any help?
thanks a lot.

tony
winston19842005
2008-12-28 15:24:55 UTC
Permalink
On 12/28/08 10:01 AM, in article
Post by c***@gmail.com
Hi All,
It is not easy to find programming manual for Pascal on the
internet.
I am trying to open a file to read, and detect if there is an error
in file operations, for example 'file does not exist'.
The following code was taken from freepascal's manual, however it
fn := paramstr (1);
Assign (source, fn); Reset (source);
if IOResult<>0 then
begin writeln ('File ', fn,' doesn't exist.'); halt; end;
As the program attempts to read a file that does not exist, runtime
Runtime error 2 at $08066E68
$08066E68
$0805E7B4
$0806D681
I am currently using freepascal.
any help?
thanks a lot.
Usually, most Pascals have error-checking turned on by default, and to be
able to use IORESULT to detect an error and handle it, you must turn off
error checking with a compile-time option.

Usually, you'd insert this just before the attempted operation, and turn it
off again after your error-handling...

{$I-} (* turn off standard I/O error handling *)
Assign (source, fn); Reset (source);
if IOResult<>0 then
begin writeln ('File ', fn,' doesn't exist.'); halt; end;

{$I+} (* turn on standard I/O error handling *)

Loading...