Important: The information in this document is obsolete and should not be used for new development.
Reading a Collection From a Collection Resource
To store a collection to disk, you can flatten a collection and write the flattened data to a file, as described in the previous section, or you can create a collection ('cltn') resource. The format of the collection resource is shown in the section "The Collection Resource" beginning on page 5-102.You can create a collection object from the information stored in a collection resource using the
GetNewCollection
function. Listing 5-26 gives an example.Listing 5-26 Reading a collection from a collection resource
OSErr ReadCollectionFromResource(short refNum, short resID, Collection* pCollection) { OSErr anErr = noErr; short saveResFile = CurResFile(); UseResFile(refNum); *pCollection = GetNewCollection(resID); if (!*pCollection) { anErr = ResError(); if (!anErr) /* if ResErr returned noErr */ anErr = resNotFound; /* then the error was resNotFound */ } UseResFile(saveResFile); return anErr; }TheReadCollectionFromResource
sample function requires three parameters:
The sample function uses the
- the reference number of the file containing the desired collection resource
- the resource ID of the desired collection resource
- a pointer to a collection object reference
CurResFile
function to determine the current resource file, saves the reference number of that resource file, and uses theUseResFile
function to indicate that the current resource file should be the resource file specified by the reference number contained in the first parameter.The sample function then uses the
GetNewCollection
function, which takes a resource ID as its only parameter, to read the information from the designated collection resource into the collection object referenced by the sample function's third parameter.Finally, the sample function checks for errors and resets the current resource file.
For more information about resource files and the
CurResFile
,UseResFile
, andResError
functions, see the chapter "Resource Manager" in Inside Macintosh: More Macintosh Toolbox.For more information about the collection resource, see "The Collection Resource" beginning on page 5-102. For more information about the
GetNewCollection
function, see the description of that function on page 5-99.