MFC : 2 dialogs : PLEASE help me!

Started by
13 comments, last by da_cobra 19 years, 1 month ago
ok, so this is what I tried now :

- created a new project : single document, database view with file support and then I chose my datasource and table
- all the other stuff I kept default

So now I had 1 dialog, I placed an edit control on it and set the variable to m_pSet->m_Bouwjaar
I ran it and voila database is working.

Now to get that second dialog working :

First : Insert->Resource->Dialog
Then I changed the ID to IDD_DIALOG2
Right mouse button->ClassWizard
Now I get the question to add a new class for my new dialog :
So : new class -> class name : CDialog2
Base class : CDialog
Dialog ID : IDD_DIALOG2
OK and OK again

So now I have my second Dialog

Now I placed a new button on the main dialog and named it "Open Dialog2"
Double clicked on it : New member function : "OnButtonOpenDialog2", OK

Now, entering the following code :

CDialog2 dlg2 ;HRESULT hresult = dlg2.DoModal() ;


and offcourse adding #include "Dialog2.h" on top of my 2DialogsView.cpp (main dialog, source file)

compile + run = everything OK, Pressing the button shows my second Dialog
Also in my editbox on my main dialog I get the value of the first record.

But now to get my database working on my second dialog!
So this is what I did :

first of all I added this line as a public member in my class CDialog2 :

CDialog2(const CMy2DialogsSet& db) ; // CMy2DialogSet is the database, right?

secondly I added the next line also in the private section of my class :

const CMy2DialogsSet& m_db;

and then in my CDialog2.cpp

CDialog2::CDialog2(const CMy2DialogsSet& db)
: m_db(db)
{

}

Now first changing
CDialog2 dlg2 ;

to

CDialog2 dlg2(*m_pSet) ;

Compiling now : 8 errors

I forgot to include the header file, so I #include "CMy2DialogsSet.h" on top of the CDialog2.h

compiling : 1 error :
error C2758: 'm_db' : must be initialized in constructor base/member initializer list
And pointed to my original constructor.

uhhhhh, what the hell?

Still doesn't work :(

I also tried setting an editbox on my second Dialog and tried to assign the variable m_db->m_Bouwjaar to it but I get the error : "invalid symbol "m_db->m_Bouwjaar" specified" :(

I hope you take the time to read this and I also hope that you can help me!

thanx in advance

[Edited by - da_cobra on March 2, 2005 12:54:29 PM]
Advertisement
ok that's a pretty simple error. a reference must be initialised on creation, i.e.
int x =0;int y = 1;int& xRef = x; // xRef now refers to xint& yRef; // ERROR!! can't create reference without initialisation


so, if I understand you correctly, in your dialog class you now have 2 constructors
//dialog2.hclass CDialog2 : public CDialog{   CDialog2(void);   CDialog2(const CMy2DialogsSet& db);};// dialog2.cppCDialog2::CDialog2(void)// eek, no reference initialisation{   //arrgh, compiler not happy...}CDialog2::CDialog2(const CMy2DialogsSet& db): m_db(db) // all cool reference is initialised{}

my advice is to delete your default constructor, as it's not necessary. this will prevent you from creating CDialog2 objects in a bad state (with no m_db).

I suggest you read up on references.
If you you plan to continue developing in C++ you will see them frequently. Good luck.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
thanx for the info :D
If I'm correct I tried to delete that first constructor yesterday, but I still got some errors, but since I'm at work right now I can't say what the errors were.
So I'll post again tonight!

ok, I tried deleting the first original constructor and my code compiled fine, but then when I ran my application and pressed the button to display my second Dialog I've got a "debug assertion failed" error :(

Program : 2Dialogs.exe
file : dlgcore.cpp
line : 497

aarrgggg, I really need to solve this problem, pls help me...

This is the code within dlgcore.cpp

int CDialog::DoModal(){	// can be constructed with a resource template or InitModalIndirect	ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||		m_lpDialogTemplate != NULL);	// load resource as necessary	LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;	HGLOBAL hDialogTemplate = m_hDialogTemplate;	HINSTANCE hInst = AfxGetResourceHandle();	if (m_lpszTemplateName != NULL)	{		hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);		HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);		hDialogTemplate = LoadResource(hInst, hResource);	}


and the error is on the first ASSERT() line
there is something new that I found out today :

In the ClassWizard, on the last tab (Class Info), I can enter a Foreign Class : "CMy2DialogsSet" (= my recordset, right?)

If I do this I can choose my record members when I declare a variable for an edit box!

but if I compile, I get an "assert error" again :'(

This topic is closed to new replies.

Advertisement