Solved

Data Exchange

Posted on 2002-03-18
6
178 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 277
while loop over for loop 7 93
tripleUp challenge 7 74
Bartender label printing - switch on and off graphics 3 10
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

26 Experts available now in Live!

Get 1:1 Help Now