🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #175

Re: Turbo Pascal file handling

#175
From: Reino de Boer
Date: Mon, 26 Mar 1990 06:50
49 lines
1646 bytes
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
Technical Details
Message-ID: <1990Mar26.065046.24879@cs.eur.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!eurtrx!euraiv1!reino
References: <18793@boulder.Colorado.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!eurtrx!euraiv1!reino
From: reino@cs.eur.nl (Reino de Boer)
Newsgroups: comp.sys.ibm.pc.programmer
Subject: Re: Turbo Pascal file handling
Message-ID: <1990Mar26.065046.24879@cs.eur.nl>
Date: 26 Mar 90 06:50:46 GMT
References: <18793@boulder.Colorado.EDU>
Organization: Erasmus Universiteit Rotterdam, dept. CS (Informatica)
Lines: 49