Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

CArchive::GetObjectSchema 

Call this function from the Serialize function to determine the version of the object that is currently being deserialized.


UINT GetObjectSchema( );

During deserialization, the version of the object being read.

Calling this function is only valid when the CArchive object is being loaded (CArchive::IsLoading returns nonzero). It should be the first call in the Serialize function and called only once. A return value of (UINT)–1 indicates that the version number is unknown.

A CObject-derived class may use VERSIONABLE_SCHEMA combined (using bitwise OR) with the schema version itself (in the IMPLEMENT_SERIAL macro) to create a "versionable object," that is, an object whose Serialize member function can read multiple versions. The default framework functionality (without VERSIONABLE_SCHEMA) is to throw an exception when the version is mismatched.

IMPLEMENT_SERIAL(CMyObject, CObject, VERSIONABLE_SCHEMA|1)

void CMyObject::Serialize(CArchive& ar) 
{
   if (ar.IsLoading())
   {
      int nVersion = ar.GetObjectSchema();

      switch(nVersion)
      {
      case 0:
         // read in previous version of 
         // this object
         break;
      case 1:
         // read in current version of
         // this object
         break;
      default:
         // report unknown version of 
         // this object
         break;
      }
   }
   else
   {
      // Normal storing code goes here
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft