Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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:
© 2014 Microsoft. All rights reserved.