Link to home
Start Free TrialLog in
Avatar of Smave
Smave

asked on

Data Exchange

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
Avatar of Smave
Smave

ASKER

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
Avatar of DanRollins
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
Avatar of Smave

ASKER

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
Avatar of Smave

ASKER

Maybe this deserves 100 points.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.