Important: The information in this document is obsolete and should not be used for new development.
GetIndResource
You can use theGetIndResourcefunction repeatedly to get handles to all resources of a given type in all resource forks open to your application.
FUNCTION GetIndResource (theType: ResType; index: Integer): Handle;
theType- A resource type.
index- An integer ranging from 1 to the number of resources of a given type returned by
CountResources, which is the number of resource types in all open resource forks.DESCRIPTION
Given an index ranging from 1 to the number of resources of a given type returned byCountResources(that is, the number of resources of that type in all resource forks open to your application), theGetIndResourcefunction returns a handle to a resource of the given type. If you callGetIndResourcerepeatedly over the entire range of the index, it returns handles to all resources of the given type in all resource forks open to your application.The function reads the resource data into memory if it's not already there, unless you've called
SetResLoadwith theloadparameter set toFALSE.
The
- IMPORTANT
- If you've called
SetResLoadwith theloadparameter set toFALSEand the data isn't already in memory,GetIndResourcereturns an empty handle (a handle whose master pointer is set to NIL). This can also happen if you read resource data for a purgeable resource into memory and then callSetResLoadwith theloadparameter set toFALSE. If the resource data is later purged and you call theGetIndResourcefunction,GetIndResourcereturns an empty handle. You should test for an empty handle in these situations. To make the handle a valid handle to resource data in memory, you can call theLoadResourceprocedure.![]()
GetIndResourcefunction returns handles for all resources in the most recently opened resource fork first, and then for those in resource forks opened earlier in reverse chronological order.
If you want to find out how many resources of a given type are in a particular resource fork, set the current resource file to that resource fork, then call
- Note
- The
UseResFileprocedure affects which file the Resource Manager searches first when looking for a particular resource; this is not the case when you useGetIndResourceto get an indexed resource.![]()
Count1Resourcesand useGet1IndResourceto get handles to the resources of that type.If you provide an index to
GetIndResourcethat's either 0 or negative,GetIndResourcereturnsNIL, and theResErrorfunction returns the result coderesNotFound. If the given index is larger than the value returned byCountResources,GetIndResourcereturnsNIL,andResErrorreturns the result coderesNotFound. If the resource to be read won't fit into memory,GetIndResourcereturnsNIL, andResErrorreturns the appropriate result code.SPECIAL CONSIDERATIONS
TheGetIndResourcefunction may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.RESULT CODES
noErr 0 No error resNotFound -192 Resource not found SEE ALSO
To check for errors, call theResErrorfunction as described on page 1-47.For a description of the
CountResourcesfunction, see page 1-93. For a description of theUseResFileprocedure, see page 1-65. For descriptions of theSetResLoadandLoadResourceprocedures, see page 1-74 and page 1-75, respectively.