Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

Please observe also the following technique :) :
C++
// 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. Please remember also
to initialize your new member(s) in the default constructor.
 
Share this answer
 
v3
Comments
nhasmita 24-Aug-11 0:00am    
Thank U for the solution...
I will try this solution and let U know..
Unfortunately the MFC serialization mechanism is fragile (at least from 'versioning' standpoint). You may use this trick:
  1. Change only the store methods.
  2. Import the 'old' archive.
  3. Update, if needed, the old objects with the new features, serialize them.
  4. Now change the load methods too.

I know, is frustrating.
 
Share this answer
 
Comments
nhasmita 23-Aug-11 23:59pm    
Thank U for the solution..
Can u pls elaborate ur solution with example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900