SYSTEM(7) or OpenResFile Gives Resource File Reference Number (36080)
This article was previously published under Q36080
SUMMARY
A "resource file reference number" is a number that allows you to
access the resource fork (area) of a file. Many of QuickBASIC's MBLC
routines use this number to access stored resources. This number is
neither an index nor a pointer -- it only has meaning to the Macintosh
System.
You can obtain a resource file reference number using the following
two methods in Macintosh QuickBASIC:
- Use the QuickBASIC SYSTEM(7) function. The SYSTEM(7) function
returns the file reference number (ref%) of the currently-running
compiled application or the currently-running interpreted source
file:
ref% = SYSTEM(7)
Never use CloseResFile on the number returned by SYSTEM(7).
- Use the OpenResFile Toolbox library routine to open external
resource files. In the following example, the OpenResFile statement
returns the file reference number of the "Demo Resources" file in
the variable ref%:
ref% = 0 ' must initialize ref% before calling OpenResFile
OpenResFile "Examples:QB Demos:Demo Resources",ref%
' ... put the body of your program here ...
' In the interpreter, the program must always CloseResFile at end:
IF ref% <> SYSTEM(7) AND ref% <> PEEKW(&H900) THEN
CloseResFile ref%
END IF
END
MORE INFORMATION
WARNING: Never use CloseResFile to close the resource fork of a
currently running source file, application, or QuickBASIC itself, or
else a "Device I/O Error" or System bomb may occur. You should only
use CloseResFile on external resource files (that were opened with
OpenResFile).
For an example of how an interpreted program can use SYSTEM(7) to get
the file reference number of its own resource area, please see the
"Icon Example" program (located in the "Demo Resources" folder of the
QuickBASIC 1.00 "Examples" disk). When run in the QuickBASIC
interpreter, "Icon Example" displays icon resources that are stored
in its own resource fork.
When "Icon Example" is compiled, the program automatically looks in
the external "Demo Resources" file for the needed resource. (The
SYSTEM(4) routine decides if the program is currently being run
interpreted or compiled.) If you want, you can use ResEdit or
Statement Mover to move the icon resources into the compiled
application "Icon Example apl", and then use SYSTEM(7) in the compiled
version instead of OpenResFile.
Modification Type: |
Minor |
Last Reviewed: |
1/9/2003 |
Keywords: |
KB36080 |
|