Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data Exchange

Posted on 2002-03-18
6
Medium Priority
?
187 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

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

Accepted Solution

by:
DanRollins earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

916 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