Modifying CDocument Member Objects :: MFC
-
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
-
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
Did you run the program in Debug mode? please try run in Release mode! or in Debug mode: ----------------------------- if( array.GetSize() > 0 ) array.RemoveAll();
-
Did you run the program in Debug mode? please try run in Release mode! or in Debug mode: ----------------------------- if( array.GetSize() > 0 ) array.RemoveAll();
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
-
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
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"
-
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"
-
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
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