home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15196 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.0 KB

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