1 Attachment(s)
A question regarding passing a variable from CView to CDocument
I am attaching a sample project. Basically what this project does is that I initialize a variable map<CString, bool*> m_mapTest in CView::OnInitialUpdate and then pass the variable to CDocument class. On the other hand, within the function OnSaveDocument defined in CDocument I check m_mapTest. To my surprise, the CString part of m_mapTest is correct but the bool* part of m_mapTest is wrong(I pass an array of bool in CView::OnInitialUpdate). Could any guru here point out why? Thanks.
Re: A question regarding passing a variable from CView to CDocument
Does storing pointers (e.g. bool*) to a document make sense anyway? What happens when you open the document from a different process instance? Do you expect those saved pointer values to be valid for a different process?
Even worse you are storing a pointers to a temporary object.
1 Attachment(s)
Re: A question regarding passing a variable from CView to CDocument
Quote:
Originally Posted by
Arjay
Does storing pointers (e.g. bool*) to a document make sense anyway? What happens when you open the document from a different process instance? Do you expect those saved pointer values to be valid for a different process?
Even worse you are storing a pointers to a temporary object.
I already fixed a problem you mentioned. I am storing a pointer to a object in heap instead of a temporary object. I attach the updated project with the post. If I don't store pointers(bool*), what is the better way to store a bunch of boolean variables? Thank you very much!
Re: A question regarding passing a variable from CView to CDocument
You can store boolean values by storing a bool (i.e. 'bool', not 'bool*'). Again, if you serialize the document to a file, you can't store pointers. It doesn't matter if you are using the heap or not because if the file is opened in another process instance, you'll be only lucky if the pointers work.
At any rate, there is no need to have the view store anything and many folks make the mistake of storing data in the view and the document. Just store the data in the document and have the view read the data out of the document. That way data is only stored in one place (and any view can access the data if need be).