why this is not called? CMyDoc::Serialize(CMyArchive& ar)
-
In my SDI project in VC6.0, I want to derive a class from CArchive(), which will have two new methods: WriteFormatString( ) and ReadFormatString( ) which basically follow the printf and scanf style. so I have this included in MyDoc.h: #include "MyArchive.h" and in the same file, changed virtual void Serialize(CArchive& ar); to virtual void Serialize(CMyArchive& ar); In MyDoc.cpp, I changed void CMyDoc::Serialize(CArchive& ar) to void CMyDoc::Serialize(CMyArchive& ar) But when I click on open or save menu items, void CMyDoc::Serialize(CMyArchive& ar) is not called. What am I missing here? Thank you very much for your help!
-
In my SDI project in VC6.0, I want to derive a class from CArchive(), which will have two new methods: WriteFormatString( ) and ReadFormatString( ) which basically follow the printf and scanf style. so I have this included in MyDoc.h: #include "MyArchive.h" and in the same file, changed virtual void Serialize(CArchive& ar); to virtual void Serialize(CMyArchive& ar); In MyDoc.cpp, I changed void CMyDoc::Serialize(CArchive& ar) to void CMyDoc::Serialize(CMyArchive& ar) But when I click on open or save menu items, void CMyDoc::Serialize(CMyArchive& ar) is not called. What am I missing here? Thank you very much for your help!
Hi, When u change the serialize(CArchive& ar) to Serialize(CMyArchive& ar) it becomes a overloaded function and the compiler expects a definition for that function. Write the function definition for Serialize(CMyArchive& ar) and override the Serialize(CArchive& ar) and call Serialize(CMyArchive& ar) from it. Hope this solves ur problem.:cool: Bye Cool Ju
-
Hi, When u change the serialize(CArchive& ar) to Serialize(CMyArchive& ar) it becomes a overloaded function and the compiler expects a definition for that function. Write the function definition for Serialize(CMyArchive& ar) and override the Serialize(CArchive& ar) and call Serialize(CMyArchive& ar) from it. Hope this solves ur problem.:cool: Bye Cool Ju
hi Cool Ju, Thank you for the direction, but I didn't quite follow. How do I override Serialize(CArchive& ar)? I tried to replace virtual void Serialize(CArchive& ar) with virtual void Serialize(CMyArchive& ar) in myDoc.h, but it doesn't work. Now what I do is in myDoc.h, add virtual BOOL OnSaveDocument(LPCTSTR lpszPathName); and in myDoc.cpp, implemented it as follows:
// TODO: copied from CDocument::OnSaveDocument(lpszPathName);, // but instead of using the default CArchive, // use CMyArchive CFileException fe; CFile* pFile = NULL; pFile = GetFile(lpszPathName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe); if (pFile == NULL) { ReportSaveLoadException(lpszPathName, &fe, TRUE, AFX_IDP_INVALID_FILENAME); return FALSE; } //CArchive saveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); CMyArchivesaveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; TRY { CWaitCursor wait; Serialize(saveArchive); // save me saveArchive.Close(); ReleaseFile(pFile, FALSE); } CATCH_ALL(e) { ReleaseFile(pFile, TRUE); #if 0 TRY { ReportSaveLoadException(lpszPathName, e, TRUE, AFX_IDP_FAILED_TO_SAVE_DOC); } END_TRY DELETE_EXCEPTION(e); #endif return FALSE; } END_CATCH_ALL SetModifiedFlag(FALSE); // back to unmodified return TRUE; // success //return CDocument::OnSaveDocument(lpszPathName);
but I got a new problem here, I have to #if 0 some of the code out, cause the compiler complains that DELETE_EXCEPTION is not defined. more hints please? :rose::rose::rose: -
hi Cool Ju, Thank you for the direction, but I didn't quite follow. How do I override Serialize(CArchive& ar)? I tried to replace virtual void Serialize(CArchive& ar) with virtual void Serialize(CMyArchive& ar) in myDoc.h, but it doesn't work. Now what I do is in myDoc.h, add virtual BOOL OnSaveDocument(LPCTSTR lpszPathName); and in myDoc.cpp, implemented it as follows:
// TODO: copied from CDocument::OnSaveDocument(lpszPathName);, // but instead of using the default CArchive, // use CMyArchive CFileException fe; CFile* pFile = NULL; pFile = GetFile(lpszPathName, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive, &fe); if (pFile == NULL) { ReportSaveLoadException(lpszPathName, &fe, TRUE, AFX_IDP_INVALID_FILENAME); return FALSE; } //CArchive saveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); CMyArchivesaveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; TRY { CWaitCursor wait; Serialize(saveArchive); // save me saveArchive.Close(); ReleaseFile(pFile, FALSE); } CATCH_ALL(e) { ReleaseFile(pFile, TRUE); #if 0 TRY { ReportSaveLoadException(lpszPathName, e, TRUE, AFX_IDP_FAILED_TO_SAVE_DOC); } END_TRY DELETE_EXCEPTION(e); #endif return FALSE; } END_CATCH_ALL SetModifiedFlag(FALSE); // back to unmodified return TRUE; // success //return CDocument::OnSaveDocument(lpszPathName);
but I got a new problem here, I have to #if 0 some of the code out, cause the compiler complains that DELETE_EXCEPTION is not defined. more hints please? :rose::rose::rose:Hi lucy, CDocument::OnSaveDocument(lpszPathName) internally calls serialize(CArchive savearchive) Donot call serialize explicitly from CMyDoc::OnSaveDocument() Instead try this BOOL CMyDoc::OnSaveDocument(LPCTSTR lpszPathName) { BOOL bRetVal = CDocument::OnSaveDocument(lpszPathName);//this will internally call serialize() } Override serialize() by void CMyDoc::Serialize(CArchive& ar) { CDocument::Serialize(ar); //first call parent's serialize CMyArchivesaveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; CWaitCursor wait; Serialize(saveArchive); // save me saveArchive.Close(); ReleaseFile(pFile, FALSE); } void CMyDoc::Serialize(CMyArchive& saveArchive) { //write ur serialization code here } Bye Cool Ju :cool: Vote for Cool Ju
-
Hi lucy, CDocument::OnSaveDocument(lpszPathName) internally calls serialize(CArchive savearchive) Donot call serialize explicitly from CMyDoc::OnSaveDocument() Instead try this BOOL CMyDoc::OnSaveDocument(LPCTSTR lpszPathName) { BOOL bRetVal = CDocument::OnSaveDocument(lpszPathName);//this will internally call serialize() } Override serialize() by void CMyDoc::Serialize(CArchive& ar) { CDocument::Serialize(ar); //first call parent's serialize CMyArchivesaveArchive(pFile, CArchive::store | CArchive::bNoFlushOnDelete); saveArchive.m_pDocument = this; saveArchive.m_bForceFlat = FALSE; CWaitCursor wait; Serialize(saveArchive); // save me saveArchive.Close(); ReleaseFile(pFile, FALSE); } void CMyDoc::Serialize(CMyArchive& saveArchive) { //write ur serialization code here } Bye Cool Ju :cool: Vote for Cool Ju