CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2011
    Posts
    23

    [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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    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

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Oct 2011
    Posts
    23

    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

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SDI Question

    Quote Originally Posted by He_That_Is View Post
    ... 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

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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?

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: SDI Question

    Quote Originally Posted by JohnCz View Post
    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.

  9. #9
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  11. #11
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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.

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: SDI Question

    Quote Originally Posted by JohnCz View Post
    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. "

  13. #13
    Join Date
    Oct 2011
    Posts
    23

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured