VC ++ 6.0中的序列化问题 [英] Serialization problem in VC++ 6.0
问题描述
我有一个使用VC ++ 6.0语言设计的项目.我有一个讲CSplitDoc的类,它是从CDocument类派生的,该类具有n个其他类对象.
我确实为每个类都应用了序列化功能.每个类都有一些变量.这些变量值以加密格式存储在文本文件中.因此,每当我的应用程序启动时,我都可以打开保存的条件文件.
我的问题是,每当我在其他任何类中添加新变量时,VC ++序列化功能都无法使用...因此,我再次必须创建加密格式的文本文件...这非常耗时.
因此有人可以建议我解决此类问题的方法吗...尽快...
预先感谢U.
I am having a project which is designed in VC++ 6.0 language. I got one class say CSplitDoc which is derived from CDocument class, this class having n numbers of other classes object.
I did apply serialization functionality for each class. Each class having some variables.. these variables values are store in a encrypted format in a text file... So whenever my application will start i can open saved condition file.
My problem is that whenever I add a new variable in any other class then VC++ serialization functionality is not working... So again I have to create encrypted format text file... which is very much time consuming.
So can someone pls suggest me some solution for such problem... asap...
Thank U in advance.
推荐答案
请同时注意以下技巧:):
Please observe also the following technique :) :
// class CYourDocument : public CDocument
/*virtual*/ void CYourDocument::Serialize(CArchive& ar)
{
static DWORD sdwVersion(2); // 2 = new member(s) = new version
CDocument::Serialize(ar);
if (ar.IsStoring()) {
ar << sdwVersion;
ar << m_ver1_member;
ar << m_ver2_member;
} else {
ar >> sdwVersion;
ar >> m_ver1_member;
if (2 <= sdwVersion) {
ar >> m_ver2_member;
}
}
}
P.S.也请记住
可以在默认构造函数中初始化您的新成员.
P.S. Please remember also
to initialize your new member(s) in the default constructor.
不幸的是,MFC
序列化机制很脆弱(至少从版本化"的角度来看).您可以使用以下技巧:
Unfortunately theMFC
serialization mechanism is fragile (at least from ''versioning'' standpoint). You may use this trick:
- 仅更改
store
方法. - 导入旧"归档文件.
- 根据需要更新具有新功能的旧对象,对其进行序列化.
- 现在也更改
load
方法.
- Change only the
store
methods. - Import the ''old'' archive.
- Update, if needed, the old objects with the new features, serialize them.
- Now change the
load
methods too.
我知道,这很令人沮丧.
I know, is frustrating.
这篇关于VC ++ 6.0中的序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!