home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!wupost!waikato.ac.nz!ldo
- From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Is a resource fork already open?
- Message-ID: <1992Sep9.154151.10708@waikato.ac.nz>
- Date: 9 Sep 92 15:41:51 +1200
- References: <39464@imag.imag.fr> <1992Sep8.153520.10687@waikato.ac.nz>
- Organization: University of Waikato, Hamilton, New Zealand
- Lines: 43
-
- In article <1992Sep8.153520.10687@waikato.ac.nz>, I posted some code
- showing you how to open a resource file and detect if it was already open.
-
- That code can actually be simplified a little. Recall that TopMapHndl only
- changes if you open a resource file that wasn't already open. So the
- ReallyOpened condition can be shortened to just "GetTopMap() <> PreviousTop".
-
- And while we're at it, we don't really need the GetTopMap routine at all.
- Just check the value of TopMapHndl itself. And in Modula-2, you can access
- low-memory globals as based variables.
-
- Putting this altogether (and noting that PreviousTop is now a Handle, not
- an IORefNum), the new code is:
-
- TYPE
- IORefNum = INTEGER;
-
- VAR
- TopMapHndl [00A50H] : Handle;
-
- Code to open the file:
-
- (* get information about current state of resource chain *)
- PreviousResFile := CurResFile();
- PreviousTop := TopMapHndl;
- (* open resource file with OpenResFile, OpenRFPerm or whatever, e g *)
- TheResFile := OpenRFPerm(FileName, VRefNum, Permission);
- ReallyOpened := TopMapHndl <> PreviousTop
-
- Code to restore things as they were:
-
- IF ReallyOpened THEN
- CloseResFile(TheResFile)
- END (*IF*);
- UseResFile(PreviousResFile)
-
- Sometimes it takes the glare of publicity to get you to think out the *proper*
- way to do something you might have been doing for years...
-
- Lawrence D'Oliveiro fone: +64-7-856-2889
- Computer Services Dept fax: +64-7-838-4066
- University of Waikato electric mail: ldo@waikato.ac.nz
- Hamilton, New Zealand 37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
-