⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index180.htm

📁 关于vc的一本问题集,很不错的,有很多精采的问题
💻 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>
&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;DECLARE_SERIAL(class_name)<Br>
</Br>
#define IMPLEMENT_DYNAMIC_SERIAL(class_name, base_class_name, wSchema) \<Br>
&nbsp;&nbsp;&nbsp;&nbsp;_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, NULL)\<Br>
&nbsp;&nbsp;&nbsp;&nbsp;static const AFX_CLASSINIT<Br>
_init_##class_name(RUNTIME_CLASS(class_name)); \<Br>
&nbsp;&nbsp;&nbsp;&nbsp;CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ pOb = (class_name*)<Br>
ar.ReadObject(RUNTIME_CLASS(class_name)); \<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ar; }<Br>
或者也可以这样实现:<Br>
</Br>
CMySerialRootDerivedClass::Serialize(CArchive& ar)<Br>
{<Br>
&nbsp;&nbsp;&nbsp;&nbsp;//CMySerialRoot::Serialize(ar);     // <- do not call this here<Br>
</Br>
&nbsp;&nbsp;&nbsp;&nbsp;if (ar.IsStoring())<Br>
&nbsp;&nbsp;&nbsp;&nbsp;{<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... store derived stuff here<Br>
&nbsp;&nbsp;&nbsp;&nbsp;}<Br>
&nbsp;&nbsp;&nbsp;&nbsp;else<Br>
&nbsp;&nbsp;&nbsp;&nbsp;{<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int nVersion = ar.GetObjectSchema();<Br>
</Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(nVersion)<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1:<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... load derived version 1 stuff here<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 2:<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... load derived version 2 stuff here<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// report unknown version of<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// this object<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<Br>
&nbsp;&nbsp;&nbsp;&nbsp;}<Br>
</Br>
&nbsp;&nbsp;&nbsp;&nbsp;// serialize the base class version information<Br>
&nbsp;&nbsp;&nbsp;&nbsp;// -> then serialize the base class<Br>
&nbsp;&nbsp;&nbsp;&nbsp;ar.SerializeClass(RUNTIME_CLASS(CMySerialRoot));<Br>
&nbsp;&nbsp;&nbsp;&nbsp;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 + -