📄 index180.htm
字号:
<html>
<style type="text/css"><!--
.p9 { font-family: "宋体"; font-size: 9pt}a {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../../../backg.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">系列化与版本的问题</font></td></tr>
<tr><td><p>
</Br>
我需要使用系列化来读取我的文件,为了保证文件能在各个版本中都能实现,我作了尽可能的努力,为什么会不成功.<Br>
</Br>
答:下面的代码是我过去使用过的,希望能对你有所帮助<Br>
</Br>
// Use this macro to fix the versioning problem in the MFC<Br>
// Place it at the beginning of your CMyObject::Serialize implementation -<Br>
// it will guarantee that the correct version of the class is written to<Br>
// and read from the archive<Br>
//<Br>
// Usage: SERIALIZE_VERSION(CMyObject)<Br>
</Br>
#define SERIALIZE_VERSION(this_class) \<Br>
ar.SerializeClass(this_class::GetRuntimeClass());<Br>
</Br>
// For classes which cannot use IMPLEMENT_SERIAL (such as abstract<Br>
// base classes). This guarantees the object can have<Br>
[Read/Write][Class/Object]<Br>
// called on it by placing a schema number in it. It also puts it in the<Br>
// list of known class names (AFX_CLASSINIT).<Br>
// Note: this is almost the same as IMPLEMENT_SERIAL_ABC<Br>
// in "MFC Internals", but this version uses AFX_CLASSINIT,<Br>
// with the result that it works!<Br>
</Br>
#define DECLARE_DYNAMIC_SERIAL(class_name) \<Br>
DECLARE_SERIAL(class_name)<Br>
</Br>
#define IMPLEMENT_DYNAMIC_SERIAL(class_name, base_class_name, wSchema) \<Br>
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, NULL)\<Br>
static const AFX_CLASSINIT<Br>
_init_##class_name(RUNTIME_CLASS(class_name)); \<Br>
CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \<Br>
{ pOb = (class_name*)<Br>
ar.ReadObject(RUNTIME_CLASS(class_name)); \<Br>
return ar; }<Br>
或者也可以这样实现:<Br>
</Br>
CMySerialRootDerivedClass::Serialize(CArchive& ar)<Br>
{<Br>
//CMySerialRoot::Serialize(ar); // <- do not call this here<Br>
</Br>
if (ar.IsStoring())<Br>
{<Br>
... store derived stuff here<Br>
}<Br>
else<Br>
{<Br>
int nVersion = ar.GetObjectSchema();<Br>
</Br>
switch(nVersion)<Br>
{<Br>
case 1:<Br>
... load derived version 1 stuff here<Br>
break;<Br>
case 2:<Br>
... load derived version 2 stuff here<Br>
break;<Br>
default:<Br>
// report unknown version of<Br>
// this object<Br>
break;<Br>
}<Br>
}<Br>
</Br>
// serialize the base class version information<Br>
// -> then serialize the base class<Br>
ar.SerializeClass(RUNTIME_CLASS(CMySerialRoot));<Br>
CMySerialRoot::Serialize( ar );<Br>
}<Br>
</Br>
</p></td></tr>
</table><p align="center"><img src="../../../logo.gif" align="center"><center><table><tr><td><a href="http://www.ourcode.net" target=_top>www.OurCode.net</a><Br>版权所有: 2002-2008</a></td></tr></table></center></p>
</body><SCRIPT LANGUAGE='JavaScript' SRC='../../../navigate_bar.js'></SCRIPT><SCRIPT LANGUAGE='JavaScript'>write_tail();</SCRIPT></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -