Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!ruuinf!ruunsa!nboogaar From: nboogaar@ruunsa.fys.ruu.nl (Martin v.d. Boogaard) Newsgroups: comp.lang.pascal Subject: Re: Problem with TP 5.5 Reset Message-ID: <1407@ruunsa.fys.ruu.nl> Date: 10 Aug 90 06:45:55 GMT References: <8096@ucrmath.ucr.edu> Organization: University of Utrecht, Dept. of Physics Lines: 48 In <8096@ucrmath.ucr.edu> pdm@ucrmath.ucr.edu (paul moore) writes: % I've been having a problem using the Reset function to determine % if a file exists, and was wondering if anybody has seen anything similar. % The code is basically: % var % F : file of MyOwn_type; % [...] % assign( F, Fname ); % {$I-} % reset( F ); % {$I+} % The program produces a runtime 002 error (file not found) and dumps % me out to DOS. [...] % Any thoughts? Well, the obvious one: supposing the file Fname really doesn't exist, do you read the ioresult value that is set when you use an I/O function like reset? Something like [...] {$I-} reset ( F ); {$I+} if ioresult > 0 then [handle error yourself] else [whatever you planned to do with the file] gives you control off the error handling and resets ioresult to 0. Beware of the `logical shortcircuit' compiler option combined with code like if Flag and ( ioresult = 0 ) [...] If Flag equals FALSE ioresult is not called and the run-time error you thought you had prevented by using {$I+} [...] {$I-} shows up at the next, probably very different, I/O statement. Off course, since Turbo Pascal is non-portable anyway, you might just as well use the built-in findfirst and findnext functions if the only purpose of the operation is to determine a file's existence. Martin J. van den Boogaard | Dept. of Atomic & Interface Physics | Debye Institute--Utrecht University P.O. Box 80.000 | NL-3508 TA Utrecht | decnet: ruunsc::boogaard the Netherlands | bitnet: boogaard@hutruu51 +31 30 532904 | internet: nboogaar@fys.ruu.nl