Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. why this is not called? CMyDoc::Serialize(CMyArchive& ar)

why this is not called? CMyDoc::Serialize(CMyArchive& ar)

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lucy 0
    wrote on last edited by
    #1

    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!

    C 1 Reply Last reply
    0
    • L lucy 0

      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!

      C Offline
      C Offline
      Cool Ju
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • C 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

        L Offline
        L Offline
        lucy 0
        wrote on last edited by
        #3

        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:

        C 1 Reply Last reply
        0
        • L lucy 0

          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:

          C Offline
          C Offline
          Cool Ju
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • C 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

            L Offline
            L Offline
            lucy 0
            wrote on last edited by
            #5

            Thank you very much, Cool Ju, the coding is working now!:laugh::cool: :rose::rose::rose::rose::rose::rose:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups