serialize args
I have been experimenting with writing a map object to file
and reading it back. I have gotten it to work, but the document
serialize is in my FormView class can only be called from the
FILE SAVE menu (through the framework code), which is fine
but I might have need to call serialize from another location in
code based on user input to data. I did not know how to supply
the argument (CArchive& ar) so I have been searching and reading
and came up with the following which does compile and does write
the object to file.
But I am wondering is this the way one should do it or is there a
better more appropriate mfc way ?
---------------------------------------------
// prepcode for calling document serialize in ClassWhatever //
CFile FileObj;
FileObj.Open(_T("TheFilename"), CFile::modeCreate | CFile::modeWrite);
CArchive ar(&FileObj, CArchive::store);
pDoc->Serialize(ar); // doc ptr from previous code
ar.Close();
--------------------------------------------
CFile FileObj;
if( FileObj.Open(_T("TheFilename"), CFile::modeRead) == FALSE )
return;
CArchive ar(&FileObj, CArchive::load);
pDoc->Serialize(ar); // doc ptr from previous code
ar.Close();
---------------------------------------------
// serialize in my document class //
void CMyDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ExpMap1.Serialize(ar); //ExpMap1 is derived from CObject
}
else
{
ExpMap1.Serialize(ar);
}
}
/// ALSO, when MS closes this news group in the coming months
/// is it going to continue it on a web forum somewhere ?