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: QuickDraw GX Environment and Utilities /
Chapter 5 - Collection Manager / Using the Collection Manager

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();
   *pCollection = GetNewCollection(resID);

   if (!*pCollection) {
      anErr = ResError();     
      if (!anErr)             /* if ResErr returned noErr */
         anErr = resNotFound; /* then the error was resNotFound */


   return anErr;
The ReadCollectionFromResource sample function requires three parameters:

The sample function uses the CurResFile function to determine the current resource file, saves the reference number of that resource file, and uses the UseResFile 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, and ResError 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.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996