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. Modifying CDocument Member Objects :: MFC

Modifying CDocument Member Objects :: MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++algorithmsdata-structurestestingbeta-testing
6 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.
  • V Offline
    V Offline
    valikac
    wrote on last edited by
    #1

    Is there a unique MFC protection that keeps an object to another class from modifying its private data? I have a CStringArray in the my document class (single-document). I pass the CStringArray object to class function belonging to another object that I instantiate inside of the document class. For example: #include myOutsideClass; void CMyClassDoc::change() { myOutsideClass *pClass = new myOutsideClass; pClass->modify(myCStringArrayObject); } ----- // Definition of modify() void CMyOutsideClass(CStringArray &array) { array.RemoveAll(); // remove all data from object array array.Add("testing"); // insert "testing" into object array } ----- Notice I pass the CStringArray object into modify using reference. Function modify(CStringArray &array) can read data from the object array. However, it cannot make permanent changes such as RemoveAll(), Add(), and/or SetAt(). Is there a internal protection algorithm that keeps another object from making permanent changes to a member object? I tried declaring the CStringArray inside of CDocument in public. That does not work either. The program crashes with an *access violation* error. Thanks, Kuphryn

    W 1 Reply Last reply
    0
    • V valikac

      Is there a unique MFC protection that keeps an object to another class from modifying its private data? I have a CStringArray in the my document class (single-document). I pass the CStringArray object to class function belonging to another object that I instantiate inside of the document class. For example: #include myOutsideClass; void CMyClassDoc::change() { myOutsideClass *pClass = new myOutsideClass; pClass->modify(myCStringArrayObject); } ----- // Definition of modify() void CMyOutsideClass(CStringArray &array) { array.RemoveAll(); // remove all data from object array array.Add("testing"); // insert "testing" into object array } ----- Notice I pass the CStringArray object into modify using reference. Function modify(CStringArray &array) can read data from the object array. However, it cannot make permanent changes such as RemoveAll(), Add(), and/or SetAt(). Is there a internal protection algorithm that keeps another object from making permanent changes to a member object? I tried declaring the CStringArray inside of CDocument in public. That does not work either. The program crashes with an *access violation* error. Thanks, Kuphryn

      W Offline
      W Offline
      wangyiming
      wrote on last edited by
      #2

      Did you run the program in Debug mode? please try run in Release mode! or in Debug mode: ----------------------------- if( array.GetSize() > 0 ) array.RemoveAll();

      V 1 Reply Last reply
      0
      • W wangyiming

        Did you run the program in Debug mode? please try run in Release mode! or in Debug mode: ----------------------------- if( array.GetSize() > 0 ) array.RemoveAll();

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        Okay. I think I know what's going on. I am working with CString object and string object. The program does not copy data from the CString object into the string object correct. For example: CString cStr = "testing"; string temp; temp = cStr; // this does not produce an error. However, it does not work temp = cStr.getat(1) // same as above What do I need to cast the cStr so the temp assigment = will work correctly? Kuphryn

        W V 2 Replies Last reply
        0
        • V valikac

          Okay. I think I know what's going on. I am working with CString object and string object. The program does not copy data from the CString object into the string object correct. For example: CString cStr = "testing"; string temp; temp = cStr; // this does not produce an error. However, it does not work temp = cStr.getat(1) // same as above What do I need to cast the cStr so the temp assigment = will work correctly? Kuphryn

          W Offline
          W Offline
          wangyiming
          wrote on last edited by
          #4

          CString cStr = "testing"; string temp = ""; char p[80]; strcpy(p,"testing"); temp = p; memset(p,0,sizeof(p)); // or temp = cStr; AfxMessageBox( temp.c_str() ); char szBuffer[80]; strcpy(szBuffer, temp.c_str() ); AfxMessageBox( szBuffer ); ------------------------------- both show messageBox "testing"

          V 1 Reply Last reply
          0
          • W wangyiming

            CString cStr = "testing"; string temp = ""; char p[80]; strcpy(p,"testing"); temp = p; memset(p,0,sizeof(p)); // or temp = cStr; AfxMessageBox( temp.c_str() ); char szBuffer[80]; strcpy(szBuffer, temp.c_str() ); AfxMessageBox( szBuffer ); ------------------------------- both show messageBox "testing"

            V Offline
            V Offline
            valikac
            wrote on last edited by
            #5

            Okay. Thanks. Kuphryn

            1 Reply Last reply
            0
            • V valikac

              Okay. I think I know what's going on. I am working with CString object and string object. The program does not copy data from the CString object into the string object correct. For example: CString cStr = "testing"; string temp; temp = cStr; // this does not produce an error. However, it does not work temp = cStr.getat(1) // same as above What do I need to cast the cStr so the temp assigment = will work correctly? Kuphryn

              V Offline
              V Offline
              valikac
              wrote on last edited by
              #6

              Thanks! I have one question. In the line: // CString myString; CEditCtrl::GetLine(1, myString.GetBuffer(255), 255); Is 255 the maximun number of characters in *that line*? I would like to get everything on that line. In general, is the size (255 in this case) referring to bytes or characters (characters * bytes = maxsize?). Kuphryn

              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