stasica@boulder.Colorado.EDU (Master, to you) (03/24/90)
I was wondering if there is any way in Turbo Pascal to close all files that have been opened during the execution of a program. (i.e., there are a lot in this program opened for different purposes). I know there is the provision that all files will be closed once program execution has ended, but is there any way to do this during run-time? In experimenting with this it seems you can open the same file multiple times. (which means eventually there are too many files for DOS to handle) Is this true, and if so, what is the original purpose? -- Sean Stasica aka "stasica@snoopy.Colorado.EDU"
reino@cs.eur.nl (Reino de Boer) (03/26/90)
stasica@boulder.Colorado.EDU (Master, to you) writes: >I was wondering if there is any way in Turbo Pascal to close all files that >have been opened during the execution of a program. (i.e., there are a lot >in this program opened for different purposes). I know there is the provision >that all files will be closed once program execution has ended, but is there >any way to do this during run-time? My own standard way of handling this is to keep files in the unit where they belong, and to have code along the following: unit u; { exported consts, types, vars, functions, procedures } implementation var f : file; open : boolean; exit_save : pointer; { other code } {$F+} procedure exit_unit; begin { other code to be executed on exit } if open then begin open := false; close( f ) end; exitproc := exit_save end; {$F-} begin open := false; { other initialization code } exit_save := exitproc; exitproc := @exit_unit end. Hope this helps -- Reino -- Reino R. A. de Boer "We want to build the right product right, right?" Erasmus University Rotterdam ( Informatica ) e-mail: reino@cs.eur.nl