Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't GetDocument

Posted on 1998-05-26
10
Medium Priority
?
399 Views
Last Modified: 2013-11-20
I'm developing a database program. I would like to place my recordset objects in the document class. I open my recordset objects in the OnCreate function of my CMDIChild derived class, this allows me to terminate and not show the window if someting goes wrong. The problem is the call to GetDocument doesn't seem to work in the OnCreate before I call the base class. I have placed my recordset objects in the CMDIChild derived class to have access to them, but this doesn't seem like good MFC programming practice. Can anyone help?
0
Comment
Question by:BlackRussian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 100 total points
ID: 1315487
You could attempt to create the recordset objects in the OnOpenDocument function and return FALSE if there is an error.

Tom

0
 

Expert Comment

by:t004024
ID: 1315488
I have this problem too. I needed to initialize an object in the document and not create the view if it fails. The problem is in the OnCreate of the frame the document is not yet associated with the frame. But I did find out that there is an overridable called LoadFrame, which is called when the association to the document occurs and this also receives a CCreateContext pointer which has the pointer to the document. I tried checking it here and returning a FALSE, if it did not succeed, it works, but my problem from the beginning was that when the view is not created, it gives me a message "Cannot create empty document" and I have been trying to get rid of this message which I could not. U could try this if U want. I had actually done the check in the OnCreate of the view and returned a -1, if the document construction failed. I would really like to know if U succeed in this.

I do not know if the OnOpenDocument will really work, because, in that case U need to create a new template of U'r own and overide the CreateNewDocument of the template and not that of the document or else U have to override the OnOpen of the menu item and do all the document creation by U'rself, which is rather painful and why do it when MFC already does it for U.
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315489
t004024,

I have no idea what you are talking about when you say
"... because, in that case U need to create a new template of U'r own and overide the CreateNewDocument of the template and not that of the document or else U have to override the OnOpen of the menu item and do all the document creation by U'rself, which is rather painful and why do it when MFC already does it for U."

You do NOT have to ANY of this. Simply return FALSE from the OnNewDocument (for new files) or OnOpenDocument (for opening files) and you that's it. That's what these functions were intended for.

Tom

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:t004024
ID: 1315490
tma,

OK, I have no idea why this happens. This is what I had tried. The documentation says that overridables for CDocument class is so so so.. So I tried to override the OnNewDocument function, put a break point there and ran the program, but it never comes to my break point. I have no idea why it does this, though the documentation says that it has to call OnNewDocument of CMyDoc.

Unless it happens that the CMultiDocTemplate is initializing a CDocument instead of CMyDoc, in which case, the OnNewDocument called will be that in CDocument and not that of CMyDoc... and that I do not know why it happens, because if we add the document template with CMyDoc as the document it should initialize CMyDoc...
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315491
>>>Unless it happens that the CMultiDocTemplate is initializing a CDocument instead of CMyDoc, in which case, the OnNewDocument called will be that in CDocument and not that of CMyDoc
==============================================
For a change, the docs are right <G>.

Did you place a break point in the Document::OnNewDocument. You could do that and then check the call stack. Also, are you sure that you are passing the runtime class info of CMyDoc to the AddDocTemplate function? What does your AddDocTemplate call look like? In addition, remember that OnNewDocument is only called for NEW documents. If you are opening the last document used, you need a breakpoint in the OnOpenDocument.

Tom
0
 

Expert Comment

by:t004024
ID: 1315492
I had done the development long back and I finished the product with the message still. Now that U pointed out I tried it again. What I forgot to do then was run and check for a successful initialization, actually it is true that for correct initialization it calls OnNewDocument.

This is what is happening, I set the break point in OnNewDocument and ran it for a successful initialization, it calls OnNewDocument, but I run it for an unsuccessful initialization and it does not work. No idea again why, though now I do know where it is giving me the message from and I know why it is not calling the OnNewDocument, that is because the Document pointer is not getting created. But my problem is this, I have a screen which gets the table to be initialized to, if the user chooses cancel, I want to stop the creation of the document, but I do not throw any exceptions or do any error processing, I just set a member to NULL and continue with the rest of the document processing, but why does it not create my document???
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315493
t004024,
In all fairness to BlackRussian and in keeping with EE rules, you need to ask your question in another thread. Once you post your own separate question, I (and other experts) can help you then. Sorry, but it's not fair to BlackRussian that we continue talking about your problem when his points are paying for this thread.

BlackRussian,
Was the answer I gave you enough, or do you need any additional information?

Tom

0
 

Expert Comment

by:t004024
ID: 1315494
Tom,

Sorry, that was not a question, that was just to confirm U'r answer that it does work and not as I had written before that it does not work, I think what is happening is something I can find out. Sorry, if it seemed like a question and I think it does seem so, it was just I was thinking while I was writing.. Thanx.
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315495
No problem. I just didn't want Linda or BlackRussian to get upset with either of us.

Tom

0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315496
Why exactly did I receive a 'D' for an answer that solves your problem??? I answered your question and on at least one other post asked if you needed additional assistance. Not exactly a great way to show other experts that they should waste their time helping you, eh????
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question