Archiving an object

To archive an object, you can access the archive directly using the TArchive class. The object must be wrapped by a TArchiveEnvelope. When you add the object, you give it a name and associate it with a particular locale. The name you give the object is used to retrieve the object later.

To add an object to an archive:

  1. Open the archive for writing by instantiating TArchive with the directory and library name of the archive. The TArchive constructor takes two additional parameters, with the following default values provided:
    ECreateMode createMode = kCreateOrOpen indicates that the specified archive should be opened if it exists and created if it does not exist.
    EAccessMode accessMode = kReadWrite indicates that the archive should be opened for both read and write access.
  2. Wrap your object in an instance of TArchiveEnvelope, specifying the archive and locale for the object in the TArchiveEnvelope constructor.
  3. Add the object to the archive by calling the member function TArchiveEnvelope::AddObject, specifying the name of the object.
For example, this code shows how to add a TImage instance, myImage, to the archive MyArchive in the directory specified by currentDirectory. The object is archived in the root locale because it is appropriate for use by all locales.

      // Open the archive.
      TDeleterFor<TArchive> archive = new TArchive( directory, TStandardText("MyArchive") );
      
      // Create a wrapper for a TImage instance.
      TLocale rootLocale = TLocale::GetRootLocale();
      TArchiveEnvelope<TImage> envelope( archive, rootLocale );
      
      // Add your TImage instance to the archive.
      TStandardText objectID( "Image" );
      envelope.AddObject( objectID, myImage );

[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