pointer question....
-
How can I change the value of my document data from another class? in my sample MFC code in MyProjectView.cpp: ... ... CMyObject* pPencil = GetDocument()->m_pPencil; // the value of GetDocument()->m_pPencil->Length is 0 pPencil->Length = 2; ... ... somehow when I execute this code, the value of m_pPencil->Length in the document is still 0. how can I change the document data from my project's View class? :(
-
How can I change the value of my document data from another class? in my sample MFC code in MyProjectView.cpp: ... ... CMyObject* pPencil = GetDocument()->m_pPencil; // the value of GetDocument()->m_pPencil->Length is 0 pPencil->Length = 2; ... ... somehow when I execute this code, the value of m_pPencil->Length in the document is still 0. how can I change the document data from my project's View class? :(
Try this: CMyView:: { GetDocument()->m_pPencil->SetPencilLength( 1 ); } or, even better, as the document should be responsible for managing the data defined within it (as with any well designed object class ) CMyView:: { GetDocument()->SetPencilLength( 1 ); } CMyDocument::SetPencilLength( int length ) { ASSERT( NULL != m_pPencil ); // And other appropriate checks! m_pPencil->SetPencilLength( length ); }