Retrieving an archived object

To retrieve an object from an archive, use the template class TArchiveEnvelope. You must know:

The class TArchive gives you access to an archive for retrieving individual archived objects.

To retrieve an object from an archive:

  1. Open the archive for accessing the contents by instantiating TArchive with the directory and library name of the archive.
    By default, the archive is opened for read and write access. You should open the archive for read-only access when possible so that other users can still access the archive while you are copying an object. You specify read-only access in the TArchive constructor.
  2. Create a TArchiveEnvelope instance to wrap the object you want to retrieve.
    If you do not specify a locale, the current locale is used. The constructor throws an exception if the specified archive does not exist.
  3. Retrieve the object by calling TArchiveEnvelope::CopyObject, specifying the name of the object.
For example, this code shows how to retrieve the object named Image, added in the previous example, from the archive MyLibrary.

      // Open the archive.
      TDeleterFor<TArchive> archive = new TArchive( directory, TStandardText("MyArchive"),
          TArchive::kOpen, TArchive::kReadOnly );
      
      // Create a wrapper for a TImage instance.
      TArchiveEnvelope<TImage> envelope( archive );
      
      // Get a copy of the TImage instance.
      TStandardText objectID( "Image" );
      TDeleterFor<TImage> retrievedImage = envelope.CopyObject( objectID );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker