-
November 16th, 2011, 03:47 AM
#1
[RESOLVED] SDI Question
I am working on an SDI Doc/View MFC application. The app seems to work fine (visually in release mode), but the document pointer returned from MyView::GetDocument() is always NULL, and I looked into it a little, and found that m_pDocument is also NULL (it's the value cast as my document type returned by GetDocument()) Can anyone help me out on this? I do need to be able to actually get the doc pointer, as it will be necessary for the remaining functionality to go in. Thank you in advance for your time and efforts in this matter.
--Victor
-
November 16th, 2011, 04:18 AM
#2
Re: SDI Question
Victor, the statndard MFC SDI application with Doc/View support does not have a problem you have described (presuming the App was created using the AppWizard).
You seem to do some changes in your project... or, perhaps, you occasionally refer to some other non-existent Doc instance?
Victor Nijegorodov
-
November 16th, 2011, 04:33 AM
#3
Re: SDI Question
Victor, one other possible cause is that you are calling GetDocument in a wrong place, e.g. in the view's class constructor.
// just looking in my crystal ball...
-
November 16th, 2011, 01:14 PM
#4
Re: SDI Question
No, it's being called in the OnDraw() function, it was put there by DevStudio. And to Victors post, No, it didn't start out a Doc/View it was a CControlBar/split type thing, with a View and no document. I converted it to a doc/view. I compared it with four other SDI's I have, and I cannot find the difference that makes the others work and this one not. Is there a secret place that the DevStudio puts the association of 'View to doc' within the project? or some obscure line of code within the .h/.cpp files? Any help is greatly appreciated.
--Victor
-
November 16th, 2011, 01:20 PM
#5
Re: SDI Question
Originally Posted by He_That_Is
... And to Victors post, No, it didn't start out a Doc/View it was a CControlBar/split type thing, with a View and no document. I converted it to a doc/view.
Well, the most probably that's a reason!
I'd recommend you to create a new project with Doc/View support (using the App Wizard) and then move your code from the old project to the new one.
Victor Nijegorodov
-
November 16th, 2011, 01:22 PM
#6
Re: SDI Question
VictorN's advice is probably the best. No telling what else you overlooked. Are you using a CSingleDocTemplate to tie everything together?
-
November 16th, 2011, 02:28 PM
#7
Re: SDI Question
Victor, how do you create your frame and view? You do not have to use document object. Are you using it? If yes, how.
As GCDEF pointed the easiest way would be to use document template, however it is not necessary.
You can write SDI-like application without a document.
I believe that when you create view class VS automatically inserts that piece of code in OnDraw and this is absolutely not necessary.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 16th, 2011, 02:32 PM
#8
Re: SDI Question
Originally Posted by JohnCz
Victor, how do you create your frame and view? You do not have to use document object. Are you using it? If yes, how.
As GCDEF pointed the easiest way would be to use document template, however it is not necessary.
You can write SDI-like application without a document.
I believe that when you create view class VS automatically inserts that piece of code in OnDraw and this is absolutely not necessary.
SDI stands for (S)ingle (D)ocument (I)interface. Saying you can write an SDI-like app without a document doesn't make sense as by definition there's a document involved. GetDocument() is in OnDraw so that the view class has somwehre to get its data. You can't make a blanket statement that it's "absolutely not necessary". In many cases it absolutely is. The OP's app has some kind of structural errors that should probably be fixed rather than ignored.
-
November 16th, 2011, 03:01 PM
#9
Re: SDI Question
I know exactly what SDI stands for; however there are circumstances under which you do not need/want document.
Good example would be an application using CFormView to mimic dialog with all functionality of the SDI app. I do not see a reason to keep a document in this case as well as in other cases with one view. Using document is not a requirement.
As for "absolutely unnecessary": it does not exclude using GetDocument it suggest it is not necessary and it depends on implementation. I may decide not to use document or if I do, I may decide using member variable that stores the pointer to the document’s object. It should be left for the programmer to decide and in many cases it creates confusion like in this case.
On the other hand I do not think that calling function to retrieve document pointer that does not change, from OnDraw (called from WM_PAINT handler) is really healthy.
Besides all: where does it say that I have to use centralized document? Even VS gives an option to create SDI without document support, doesn’t it? SDI is Single Documnet Interface, as the type of the application and I am not sure if this implies necessity of the document usage.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 16th, 2011, 03:07 PM
#10
Re: SDI Question
I understand what you're saying, but given the opening line of the OP, "I am working on an SDI Doc/View MFC application", your advice may be confusing.
-
November 16th, 2011, 03:24 PM
#11
Re: SDI Question
I think OP is not using doc/view architecture from the rest of the post. So I am not sure where confusion is.
The best if we let OP to clarify that.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 16th, 2011, 03:27 PM
#12
Re: SDI Question
Originally Posted by JohnCz
I think OP is not using doc/view architecture from the rest of the post. So I am not sure where confusion is.
The best if we let OP to clarify that.
"I do need to be able to actually get the doc pointer, as it will be necessary for the remaining functionality to go in. "
-
November 16th, 2011, 05:53 PM
#13
Re: SDI Question
Yes, sadly enough, I must agree . . . Rebuild the project as a proper app. Thanks for all of the input.
--Victor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|