Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble with file handling

11 views
Skip to first unread message

climb...@gmail.com

unread,
Dec 28, 2008, 10:01:43 AM12/28/08
to
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

unread,
Dec 28, 2008, 10:24:55 AM12/28/08
to
On 12/28/08 10:01 AM, in article
6f0c66b1-e228-4df7...@v42g2000yqj.googlegroups.com,
"climb...@gmail.com" <climb...@gmail.com> wrote:

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 *)

0 new messages