Solved

Data Exchange

Posted on 2002-03-18
6
177 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
  • 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
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

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

12 Experts available now in Live!

Get 1:1 Help Now