15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Using CRecordView on a Dialog Box

Mihir Dalal -- m_dalal@ECE.concordia.CA
Thursday, September 05, 1996


Environment: MSVC 1.5, Windows 95, IBM PC

In MFC, the CRecordView is a class derived from the CFormView, which aids 
in connecting databases to FormViews.

I am trying to communicate with a database from a Modal Dialog box, but 
the CRecordView won't allow me to do so, since it is derived from 
CFormView and (not CDialog), which means it won't support the DOModal() 
member function of CDialog.  An way out ???  

Mihir. 



John Ferguson -- johnf@uvsg.com
Friday, September 06, 1996

use the CRecordset classes to get your data. It gives you a nice level
of control.
in the Appwizard, use "include .h files"

>----------
>From: 	Mihir Dalal[SMTP:m_dalal@ECE.concordia.CA]
>Sent: 	Thursday, September 05, 1996 11:17 AM
>To: 	mfc-l@netcom.com
>Subject: 	Using CRecordView on a Dialog Box
>
>
>Environment: MSVC 1.5, Windows 95, IBM PC
>
>In MFC, the CRecordView is a class derived from the CFormView, which aids 
>in connecting databases to FormViews.
>
>I am trying to communicate with a database from a Modal Dialog box, but 
>the CRecordView won't allow me to do so, since it is derived from 
>CFormView and (not CDialog), which means it won't support the DOModal() 
>member function of CDialog.  An way out ???  
>
>Mihir. 
>



Vincent Mascart -- 100425.1337@compuserve.com
Saturday, September 07, 1996

>From: 	Mihir Dalal
>Sent: 	vendredi 6 septembre 1996 3:24
>To: 	INTERNET:MFC-L@NETCOM.COM
>Subject: 	Using CRecordView on a Dialog Box
>
>Environment: MSVC 1.5, Windows 95, IBM PC
>
>In MFC, the CRecordView is a class derived from the CFormView, which aids 
>in connecting databases to FormViews.
>
>I am trying to communicate with a database from a Modal Dialog box, but 
>the CRecordView won't allow me to do so, since it is derived from 
>CFormView and (not CDialog), which means it won't support the DOModal() 
>member function of CDialog.  An way out ???  
>
>Mihir. 

Why not use a copy of the template you use for your CRecordView and change its
style attributes. So you will be able to use it as a dialog.

Vincent Mascart
100425.1337@compuserve.com





Mihir Dalal -- m_dalal@ECE.concordia.CA
Sunday, September 08, 1996

[Mini-digest: 2 responses]

On 7 Sep 1996, Vincent Mascart wrote:

> >From: 	Mihir Dalal
> >Sent: 	vendredi 6 septembre 1996 3:24
> >To: 	INTERNET:MFC-L@NETCOM.COM
> >Subject: 	Using CRecordView on a Dialog Box
> >
> >Environment: MSVC 1.5, Windows 95, IBM PC
> >
> >In MFC, the CRecordView is a class derived from the CFormView, which aids 
> >in connecting databases to FormViews.
> >
> >I am trying to communicate with a database from a Modal Dialog box, but 
> >the CRecordView won't allow me to do so, since it is derived from 
> >CFormView and (not CDialog), which means it won't support the DOModal() 
> >member function of CDialog.  An way out ???  
> >
> >Mihir. 
> 
> Why not use a copy of the template you use for your CRecordView and change its
> style attributes. So you will be able to use it as a dialog.
> 
> Vincent Mascart
> 100425.1337@compuserve.com
> 
> 

Vincent,

What you have suggested is right, but that solves only half of the 
problem. Changing the style attribute of the template merely declares the 
template as a Dialog Box instead of a Form view. 

The real problem is in invoking this template at run time, once declared 
as a Modal Dialog Box. Conventionally Dialog Boxes are invoked at run time by 
Menu clicks using the DoModal() member function. This member function is 
not supported by CRecordView (since it is derived from CFormView in mfc), 
the mfc class from which my view class is derived. If I try to derive my 
view class from CDialog (which does support the DoModal() member funciton), 
I can invoke the template as a dialog box, but I lose the database 
functionality which is offered by the special CRecordView class of mfc.

As someone suggested the problem is best solved by what is known as 
"coinheritance" , which means I need to derive my view class from two mfc 
classes namely CRecordView and CDialog. This is one of the solutions, but 
I feel that is too complicated an operation for implementing a very 
simple thing. There must be a simpler way out.

IT WOULD BE OF GREAT HELP, IF SOMEONE COULD PROVIDE A SAMPLE CODE FOR THIS 
KIND OF AN IMPLEMENTATION.

Mihir. 
(m_dalal@ece.concordia.ca)
University Researcher.
-----From: Mihir Dalal 

John,

What you have suggested is just part of the problem. The CRecordSet class 
does provide excellent handling of databases. The problem is, once 
connected to the database via CRecordSet, the mfc offers CRecordView to 
view and update the database at run time.

The CRecordView is a class derived from CFormView in the mfc, which means 
it supports only form view like visual interface. Instead of this, if I 
try to use a Modal Dialog Box, as a visual interface, I have trouble.  

The CRecordView, does not support the member function DoModal() which is 
conventionally used to invoke Dialog Boxes at run time. This means there 
is no straightforward way of connecting a Dialog Box interface to 
CRecordSet, which inturn connects you to the database. 

Mihir. 
m_dalal@ece.concordia.ca
University Researcher. 



Jean-Francois Bertrand -- monsieur@step.polymtl.ca
Monday, October 28, 1996

[Mini-digest: 2 responses]

----------
> From: Mihir Dalal 
> To: mfc-l@netcom.com
> Cc: 'MFC-List' 
> Subject: RE: Using CRecordView on a Dialog Box
> Date: Sunday, September 08, 1996 8:11 AM
> 
> [Mini-digest: 2 responses]
> 
> On 7 Sep 1996, Vincent Mascart wrote:
> 
> > >From: 	Mihir Dalal
> > >Sent: 	vendredi 6 septembre 1996 3:24
> > >To: 	INTERNET:MFC-L@NETCOM.COM
> > >Subject: 	Using CRecordView on a Dialog Box
> > >
> > >Environment: MSVC 1.5, Windows 95, IBM PC
> > >
> > >In MFC, the CRecordView is a class derived from the CFormView, which
aids 
> > >in connecting databases to FormViews.
> > >
> > >I am trying to communicate with a database from a Modal Dialog box,
but 
> > >the CRecordView won't allow me to do so, since it is derived from 
> > >CFormView and (not CDialog), which means it won't support the
DOModal() 
> > >member function of CDialog.  An way out ???  
> > >
> > >Mihir. 
> > 
> > Why not use a copy of the template you use for your CRecordView and
change its
> > style attributes. So you will be able to use it as a dialog.
> > 
> > Vincent Mascart
> > 100425.1337@compuserve.com
> > 
> > 
> 
> Vincent,
> 
> What you have suggested is right, but that solves only half of the 
> problem. Changing the style attribute of the template merely declares the

> template as a Dialog Box instead of a Form view. 
> 
> The real problem is in invoking this template at run time, once declared 
> as a Modal Dialog Box. Conventionally Dialog Boxes are invoked at run
time by 
> Menu clicks using the DoModal() member function. This member function is 
> not supported by CRecordView (since it is derived from CFormView in mfc),

> the mfc class from which my view class is derived. If I try to derive my 
> view class from CDialog (which does support the DoModal() member
funciton), 
> I can invoke the template as a dialog box, but I lose the database 
> functionality which is offered by the special CRecordView class of mfc.
> 
> As someone suggested the problem is best solved by what is known as 
> "coinheritance" , which means I need to derive my view class from two mfc

> classes namely CRecordView and CDialog. This is one of the solutions, but

> I feel that is too complicated an operation for implementing a very 
> simple thing. There must be a simpler way out.
> 
> IT WOULD BE OF GREAT HELP, IF SOMEONE COULD PROVIDE A SAMPLE CODE FOR
THIS 
> KIND OF AN IMPLEMENTATION.
> 
> Mihir. 
> (m_dalal@ece.concordia.ca)
> University Researcher.
> -----From: Mihir Dalal 
> 
> John,
> 
> What you have suggested is just part of the problem. The CRecordSet class

> does provide excellent handling of databases. The problem is, once 
> connected to the database via CRecordSet, the mfc offers CRecordView to 
> view and update the database at run time.
> 
> The CRecordView is a class derived from CFormView in the mfc, which means

> it supports only form view like visual interface. Instead of this, if I 
> try to use a Modal Dialog Box, as a visual interface, I have trouble.  
> 
> The CRecordView, does not support the member function DoModal() which is 
> conventionally used to invoke Dialog Boxes at run time. This means there 
> is no straightforward way of connecting a Dialog Box interface to 
> CRecordSet, which inturn connects you to the database. 
> 
> Mihir. 
> m_dalal@ece.concordia.ca
> University Researcher. 

Hi,
I guess you did not read the functionnality of CRecordView Correctly or I
did not understand your message.  All the functionnality of the CRecordView
is in the CRecordSet.  The only thing you need to do if you want to have a
dialog to scroll in a dataset is to pass a pointer to your dataset in your
CMyDialog and use all the functionnality of the CRecordSet in the message
loop of your dialog.  The only thing that CRecordView offers is to
SetFiledsDirty when you UpdateData() when you want to change something in
your dataset, and you can do that yourself (3 lines of code).  I have a
sample code that I could send you if this is your problem. You will be able
to View and Update your database a runtime.  You could also do a little
searching on CRecordView to see how you could update at runtime(very easy).

Just e-mail me
Jean-Francois Bertrand
monsieur@step.polymtl.ca

-----From: Mihir Dalal 

Jean,

Firstly, thanks a lot for responding. I will put down my question now in 
a very narrow way so that you clearly understand what my real problem is. 

What you have suggested is right. I do agree that passing the "pointer to 
the dataset" to my CMyDialog will solve the problem. My problem now is HOW 
TO PASS THE POINTER ???

I have written some code (actually very similar to what is shown in the 
ENROLL sample in MSVC) which does the passing of pointers in case of a 
CRecordView. 

It goes something like this:

void CVehView::OnInitialUpdate()
{
	
	m_pSelection = NULL;    // initialize selection
	
	// Make m_pSet point to CVehSet.
        m_pSet = &GetDocument()->m_vehSet;// m_vehSet is the "pointer to dbase"
	                                  // & goes to m_pSet indirectly via 
                                          // the document. Note the use of
                                          // GetDocument() to do that.  
	

        // Make pDoc point to CCliSet & sort the dbase by Client_Name
	CAvlDoc* pDoc = GetDocument();
	pDoc->m_cliSet.m_strSort = "Client_Name";// m_cliSet is another dbase
	if (!pDoc->m_cliSet.Open())              // pointer being passed to 
	return;                                  // to the CRecordView. Note  
                                                 // Note the use of pDoc. 
	
        // CVehSet m_vehSet;
        // CCliSet c_cliSet; // are the lines in the document class 
                             // for defining m_vehSet/m_cliSet.  

        // Filter, parameterize and sort the CVehSet recordset 
	m_pSet->m_strFilter = "Client_Name = ?";
	m_pSet->m_strClient_NameParam = pDoc->m_cliSet.m_Client_Name;
	m_pSet->m_strSort = "Veh_No";
	m_pSet->m_pDatabase = pDoc->m_cliSet.m_pDatabase; 

	// m_pSet holds the CVehSet & pDoc holds the CCliSet pointers.
	
	
	CRecordView::OnInitialUpdate();
    
        // Fill the combo box on the recordview.
        // Again note the problamatic use of pDoc which cannot be ported 
        // to a CDialog. 
        
        m_ctlClient_Name.ResetContent();
	if (pDoc->m_cliSet.IsOpen())
		{ 
		while (!pDoc->m_cliSet.IsEOF())
			{
			m_ctlClient_Name.AddString(pDoc->m_cliSet.m_Client_Name);
			pDoc->m_cliSet.MoveNext();
			}
		}
		m_ctlClient_Name.SetCurSel(0);

   	
}
	

What it basically does, is that is passes the "pointers to datasets" to the 
CRecordView, indirectly from the doucment class (deliberately, to make 
use of the document/view architecture). Finally it loads a combobox on 
the recordview.   

I also want the same behavior, but on a CMyDialog, instead of CRecordview. 
When I port it to CMyDialog some basic functions & variables like 
"GetDocument()", "pDoc" etc. are not supported in the CMyDialog since 
CmyDialog is derived form CDialog which does not have document support 
implicitly. 

I could do one thing. I could go to the MSVC core files & copy the 
GetDocument(), declare pDoc etc. in my CMyDialog. But, I believe, there 
should be a simpler way out. 

Say, I want to avoid going to the doucment class. If I can directly pass 
my "pointer to dataset" to CMyDialog instead of first passing it to a 
document class, then associating that document class to my CMyDialog & 
then finally passing the pointer as shown above, that will definitely 
solve the problem. 

You see, my problem then reduces to HOW TO PASS "pointers to datasets" TO 
"Modal Dialog box classes".(by avoiding the reference to a doucment class 
in between)

As for the " SetFiledsDirty", thanks for that info too. I didn't knew 
that that is all what CRecordView has to do with databases. If you could 
mail me the code for "How to do that in my dialog box case ??" please. 

Lastly, I feel this is a very common situation encountered by 
programmers. Microsoft has a sample which shows you how to hook up 
CRecordViews to databases, but there is no mention of whether similar 
techniques can be employed for Modal Dialog Boxes. 

Infact, most of the times a programmer wants to hook up his/her database 
to a dialog box rather than a form view (which CRecordView offers). One 
usually accepts i/p from the user through a dialog box rather than a 
silly looking formview which remains on the screen all the time.

I have been working on this problem for quite some time, & I know of a 
web site tutorial which specifically shows you how to hook dbase classes 
to Dialog Boxes, but unfortuantely it avoids the "passing of pointers", 
instead it tackles the problem  by going through some long & tedious 
procedure. 

In case, you want to refer to it, just send me a mail, & I will send you 
the URL for that site.   

Thanks once again for your help,
Mihir. 
(University Researcher)
m_dalal@ece.concordia.ca

P.S. If you have implemented such a hook up between a dialog box & a 
     recordset, please mail me the code for the CYourDialog class. It 
     should be of great help to me. 



Richard Braley -- braley@sky.net
Tuesday, October 29, 1996

[Mini-digest: 3 responses]

If all you want to do is pass a pointer to a CRecordSet object, why =
don't you just declare a member variable of the appropriate type and =
assign it to the recordset you want access to prior to calling DoModal? =
Treat it just as you would any other variable which is passed to =
CDialog. Wouldn't this do want you want?




Vincent Mascart -- 100425.1337@compuserve.com
Thursday, October 31, 1996

>-----From: Mihir Dalal 
>
>[snip]
>
>What you have suggested is right. I do agree that passing the "pointer to 
>the dataset" to my CMyDialog will solve the problem. My problem now is HOW 
>TO PASS THE POINTER ???

Just add a CRecordset* parameter to the constructor of your CDialog derived
class.

>[snip]
>What it basically does, is that is passes the "pointers to datasets" to the 
>CRecordView, indirectly from the doucment class (deliberately, to make 
>use of the document/view architecture). Finally it loads a combobox on 
>the recordview.   
>[snip]
>You see, my problem then reduces to HOW TO PASS "pointers to datasets" TO 
>"Modal Dialog box classes".(by avoiding the reference to a doucment class 
>in between)

Since your dialog box is modal, you don't need these kind of indirect mechanism
since you will construct your dialog, passing the pointer you need, then call
its DoModal() function.

Vincent Mascart
100425.1337@compuserve.com





| Вернуться в корень Архива |