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::OnIniti alUpdate() function looks like this:
void CTheoFrontEndView::OnIniti alUpdate()
{
//start code generated by MFC
m_pSet = &GetDocument()->m_theoFron tEndSet;
CDaoRecordView::OnInitialU pdate();
GetParentFrame()->RecalcLa yout();
ResizeParentToFit();
//end code generated by MFC
//start of my code
m_pSet->MoveLast();
m_RecordCNT=m_pSet->GetRec ordCount() ; //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::DoDataE xchange(CD ataExchang e* 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
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::OnIniti
void CTheoFrontEndView::OnIniti
{
//start code generated by MFC
m_pSet = &GetDocument()->m_theoFron
CDaoRecordView::OnInitialU
GetParentFrame()->RecalcLa
ResizeParentToFit();
//end code generated by MFC
//start of my code
m_pSet->MoveLast();
m_RecordCNT=m_pSet->GetRec
//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::DoDataE
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
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
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
ASKER
Yes the class wizard did add:
DDX_Text(pDX, IDC_EDIT_RecordCNT, m_RecordCNT);
to the
void CTheoFrontEndView::DoDataE xchange(CD ataExchang e* pDX)
function.
Somehow the
m_RecordCNT
member variable is loosing it values after the
void CTheoFrontEndView::OnIniti alUpdate()
function is run.
I thought the member variable is global within the CTheoFrontEndView scope.
Ace
DDX_Text(pDX, IDC_EDIT_RecordCNT, m_RecordCNT);
to the
void CTheoFrontEndView::DoDataE
function.
Somehow the
m_RecordCNT
member variable is loosing it values after the
void CTheoFrontEndView::OnIniti
function is run.
I thought the member variable is global within the CTheoFrontEndView scope.
Ace
ASKER
Maybe this deserves 100 points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi S,
As Dan has said, call UpdateData(FALSE);
The problem with your code is that CDaoRecordView::OnInitialU pdate() calls UpdateData(FALSE) before you set the value of m_RecordCNT
void CTheoFrontEndView::OnIniti alUpdate()
{
//start code generated by MFC
m_pSet = &GetDocument()->m_theoFron tEndSet;
CDaoRecordView::OnInitialU pdate();
GetParentFrame()->RecalcLa yout();
ResizeParentToFit();
//end code generated by MFC
//start of my code
m_pSet->MoveLast();
m_RecordCNT=m_pSet->GetRec ordCount() ; //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.
As Dan has said, call UpdateData(FALSE);
The problem with your code is that CDaoRecordView::OnInitialU
void CTheoFrontEndView::OnIniti
{
//start code generated by MFC
m_pSet = &GetDocument()->m_theoFron
CDaoRecordView::OnInitialU
GetParentFrame()->RecalcLa
ResizeParentToFit();
//end code generated by MFC
//start of my code
m_pSet->MoveLast();
m_RecordCNT=m_pSet->GetRec
to
UpdateData(FALSE);
//end of my code
}
So the way to fix the problem is to add UpdateData as above.
Regards.
ASKER
void CTheoFrontEndView::DoDataE
is getting called.
But somehow the member variable
long m_RecordCNT;
is getting reset to 0 after the
void CTheoFrontEndView::OnIniti
is executed.
I moved the statement
m_RecordCNT=m_pSet->GetRec
from the
void CTheoFrontEndView::OnIniti
function to the
void CTheoFrontEndView::DoDataE
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