Solved

Data Exchange

Posted on 2002-03-18
6
185 Views
Last Modified: 2013-11-20
info:
The MFC application I am writing has Database DAO file support.

Its called TheoFrontEnd

I have an edit box on my main form that is displaying the wrong value.

The control is:
IDC_EDIT_RecordCNT

Its member varible is:
long     m_RecordCNT;

The applications CTheoFrontEndView::OnInitialUpdate()function looks like this:
void CTheoFrontEndView::OnInitialUpdate()
{
        //start code generated by MFC
     m_pSet = &GetDocument()->m_theoFrontEndSet;
     CDaoRecordView::OnInitialUpdate();
     GetParentFrame()->RecalcLayout();
     ResizeParentToFit();
        //end code generated by MFC

        //start of my code
     m_pSet->MoveLast();
     m_RecordCNT=m_pSet->GetRecordCount(); //counts the number of records in the table I have linked to
        //end of my code
}

When I debug the app. the member variable m_RecordCNT DOES get the correct value!  However, that values does not show up in the edit box that the member variable is attached to.

From what I can tell the
void CTheoFrontEndView::DoDataExchange(CDataExchange* pDX)
function is never getting called. (maybe)

Or

Maybe I need to invalidate the rectangle that the edit box occupies.  I don't know.

What do you think?

Thanx
Ace
0
Comment
Question by:Smave
[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
  • 3
  • 2
6 Comments
 

Author Comment

by:Smave
ID: 6878745
OK.  After little more investigation the
void CTheoFrontEndView::DoDataExchange(CDataExchange* pDX)
is getting called.

But somehow the member variable
long     m_RecordCNT;
is getting reset to 0 after the
void CTheoFrontEndView::OnInitialUpdate()
is executed.

I moved the statement
 m_RecordCNT=m_pSet->GetRecordCount(); //counts the number of records in the table I have linked to
from the
void CTheoFrontEndView::OnInitialUpdate()
function to the
void CTheoFrontEndView::DoDataExchange(CDataExchange* pDX)
function.
Now the correct value does display in the edit box.

This fix works, but it is unacceptable.  I only need to count the records once, not every time the view is changed.

Why is the member variable loosing its value?

Thanx
Dave
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6878752
To transfer the data from a variable to a screen element, use
   UpdateData( FALSE );

This assumes that you have used ClassWizard to associate a m_RecordCNT with the edit control.  If so, there will be something like this in your DoDataExchange fn:

     DDX_Text(pDX, IDC_EDIT1, m_sEdit1);

-- Dan
0
 

Author Comment

by:Smave
ID: 6878816
Yes the class wizard did add:
DDX_Text(pDX, IDC_EDIT_RecordCNT, m_RecordCNT);
to the
void CTheoFrontEndView::DoDataExchange(CDataExchange* pDX)
function.

Somehow the
m_RecordCNT
member variable is loosing it values after the
void CTheoFrontEndView::OnInitialUpdate()
function is run.

I thought the member variable is global within the CTheoFrontEndView scope.

Ace
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:Smave
ID: 6878829
Maybe this deserves 100 points.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 6878853
Did you use  
   UpdateData( FALSE );
after assigning the desired value to m_RecordCNT?  There are other things to try, but that is the first and you did not mention trying it.

-- Dan
0
 
LVL 6

Expert Comment

by:peterdownes
ID: 6878887
Hi S,

As Dan has said, call UpdateData(FALSE);

The problem with your code is that CDaoRecordView::OnInitialUpdate() calls UpdateData(FALSE) before you set the value of m_RecordCNT

void CTheoFrontEndView::OnInitialUpdate()
{
   //start code generated by MFC
   m_pSet = &GetDocument()->m_theoFrontEndSet;
   CDaoRecordView::OnInitialUpdate();
   GetParentFrame()->RecalcLayout();
   ResizeParentToFit();
   //end code generated by MFC

   //start of my code
   m_pSet->MoveLast();
   m_RecordCNT=m_pSet->GetRecordCount(); //counts the number of records in the table I have linked
to
   UpdateData(FALSE);
   //end of my code
}

So the way to fix the problem is to add UpdateData as above.

Regards.
0

Featured Post

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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. …
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

635 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