Solved

Can't GetDocument

Posted on 1998-05-26
10
384 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
  • 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video discusses moving either the default database or any database to a new volume.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now