Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Counting and Listing Resource Types


GetIndResource

You can use the GetIndResource function 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 by CountResources (that is, the number of resources of that type in all resource forks open to your application), the GetIndResource function returns a handle to a resource of the given type. If you call GetIndResource repeatedly 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 SetResLoad with the load parameter set to FALSE.

IMPORTANT
If you've called SetResLoad with the load parameter set to FALSE and the data isn't already in memory, GetIndResource returns 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 call SetResLoad with the load parameter set to FALSE. If the resource data is later purged and you call the GetIndResource function, GetIndResource returns 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 the LoadResource procedure.
The GetIndResource function 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.

Note
The UseResFile procedure affects which file the Resource Manager searches first when looking for a particular resource; this is not the case when you use GetIndResource to get an indexed resource.
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 Count1Resources and use Get1IndResource to get handles to the resources of that type.

If you provide an index to GetIndResource that's either 0 or negative, GetIndResource returns NIL, and the ResError function returns the result code resNotFound. If the given index is larger than the value returned by CountResources, GetIndResource returns NIL,and ResError returns the result code resNotFound. If the resource to be read won't fit into memory, GetIndResource returns NIL, and ResError returns the appropriate result code.

SPECIAL CONSIDERATIONS
The GetIndResource function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

RESULT CODES
noErr0No error
resNotFound-192Resource not found
SEE ALSO
To check for errors, call the ResError function as described on page 1-47.

For a description of the CountResources function, see page 1-93. For a description of the UseResFile procedure, see page 1-65. For descriptions of the SetResLoad and LoadResource procedures, see page 1-74 and page 1-75, respectively.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996