Re: serialize args
On May 19, 4:53 pm, "RB" <NoMail@NoSpam> wrote:
Again thanks Goran for all the extremely detailed information.
I have saved it and will examine it thoroughly included trying it
in a separate project to get all of what you are explaining.
Prior to reading this current reply from you I have been doing
some stepping thru code called outside of "my code" to try and get
a better picture of what was going on. And I found the following:
Keep in mind your recent post will also shed light on this but it
will take me awhile to decipher thru all you wrote. Additionally this
is just merely communciating, if the below is redundant to you
(or wrong ascertations on my part) then disregard it. I don't expect you
to reply to this since you have given me plenty that I have not yet had
a chance (but will ) digest.
----the following is within MyDocClass::Serialize function
CDocument::Serialize(ar); //Docs say to call base class func but I=
think this is
// for a generic CObject derivation not CDocument derivation,=
because if
// you step into this it calls the CObject base and it simply=
goes thru this do
// nothing code and returns
// _AFX_IN=
LINE void CObject::Serialize(CArchive&)
// { /* CO=
bject does not serialize anything by default */ }
Yes, and yet, as you found out, MFC code itself consistently calls
base class's Serialize, and that, without calling
SerializeClass(base). So are they not listening to their own advice?
Well, often they don't, but I think that's not the case here. I think
the reason why they don't SerializeClass(base) is this: quite often,
when user code serializes MFC containers, it simply does
m_MFCContainer.Serialize(ar);
And that works. So if MFC ever tries to change serialization of the
smallest thing in MFC, I bet you that there will be "broken
serialization!" cries up to high heavens. So CObject::Serialize will,
as far as load/store from the archive is concerned, stay empty
forever. It might do something else, not related to "on-disk" state
(e.g. add m_bLoadedFromFile flag). So what we, the users, should do,
is:
* when base class is MFC class, call
__super::Serialize.
* when base class is something of our own, call
SerializeClass(base);
__super::Serialize
* eventually, when we are certain that base class will never-ever-ever
change the schema, we can skip SerializeClass (not recommended, though
- us people are bad at telling future).
( This is all speculation and guessing on my part. Hopefully educated
enough, though, and it works for me, from MFC versions 4 to 9 ;-) )
Goran.