Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Call this function from the Serialize function to determine the version of the object that is currently being deserialized.
UINT GetObjectSchema( );
Return Value
During deserialization, the version of the object being read.
Remarks
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.
Example
IMPLEMENT_SERIAL(CSchemaObject, CObject, VERSIONABLE_SCHEMA | 1)
void CSchemaObject::Serialize(CArchive& ar)
{
CObject::Serialize(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
}
}
Requirements
Header: afx.h