pdm@ucrmath.ucr.edu (paul moore) (08/10/90)
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. This unit is part of a much larger program, and other units in the program behave properly when performing the same operation. Any thoughts? paul
nboogaar@ruunsa.fys.ruu.nl (Martin v.d. Boogaard) (08/10/90)
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