Click to See Complete Forum and Search --> : Using Dialog Data Exchange


TrimTrom
July 24th, 1999, 12:56 PM
Hello,

I am a beginner VC++ 6.0 professional programmer using Win98.

I have the following problem:

I am trying to use dialog data exchange (DDX) with a dialog box in my
application, in order to retrieve data from a database table, edit it,
and then save it. I am however having problems.

I have created a dialogbox resource, and associated it with a CDialog
class in ClassWizard. In the Foreigh Class box I have selected a
CDAORecordset class I had created previously. In the Foreign Variable
box I put the name "m_pSet". I then created member variables for all my
edit boxes in the dialog, selecting fields from the dropdown in the
Member Variable section of ClassWizard.

After this, the ClassWizard generated the following method in my CDialog
class:

void CRView3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRView3)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_DisplayName, m_pSet);
DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_Email, m_pSet);
//}}AFX_DATA_MAP
}



It also initialised m_pSet to NULL in the CDialog constructor. But it
did no more than that.

My first problem is that ClassWizard created no code actually to open my
recordset class. So I did that as follows:

void CRView3::GetRecordset()
{
m_pSet = new CAddrRset1(NULL);
m_pSet->Open();
}



After the above measures the dialog box worked OK in that it presented
me with the right data. However, it won't save any changes I make back
to the database. This is my second problem. I thought that all this
was taken care of by dialog data exchange.

I would be very grateful for code showing how to set up dialog data
exchange so that it works properly and saves changes back to the
database.

Thanks,
TrimTrom

----------------------------------
Email: paul.trimming_nospam@dial.pipex.com
Surrey, England
----------------------------------

Paul Belikian
July 24th, 1999, 03:49 PM
Hi,

The DDX functions only update the member variables. For example, taking the data from an edit box and putting it into a member variable of CString. What you do with the vars is left up to you. Typically the caller initializes the variables before calling the dialog and reads them after the dialog is closed successfully. I know this doesn't answer your question directly, but hopefully it helps.



Regards,

Paul Belikian

John Killingbeck
July 24th, 1999, 10:01 PM
Here is a sample of a dialog box call, titled Parameters. The call is in the View class and created from the ID_PARAMETERS Command function generated by the ClassWizard. This is a multithreading program, so there are hMutexs. It shows data initialization before calling the dialog box and retrieving the new data when the box is exited with the OK button:

// Parameters dialog box routine.
void CMandelbrotView::OnParameters()
{
CParameters dlg;

// Initialize dialog data
::WaitForSingleObject( HMutexActive, INFINITE );
dlg.m_dCiMax = parametersActive.m_dCiMax;
dlg.m_dCiMin = parametersActive.m_dCiMin;
dlg.m_dCrMax = parametersActive.m_dCrMax;
dlg.m_dCrMin = parametersActive.m_dCrMin;
dlg.m_dLMaximum = parametersActive.m_dLMax;
dlg.m_nNMax = parametersActive.m_nNMax;
dlg.m_nPalSize = parametersActive.m_nPalSize;
dlg.m_nColorShift = parametersActive.m_nColorShift;
::ReleaseMutex( HMutexActive );

// Invoke the dialog box
if ( dlg.DoModal() == IDOK )
{
// If dialog box is left with OK button make sure
// Maximum and minimum values are properly set.
// Exit with no change if Max = Min in a set.

if ( ( dlg.m_dCiMax != dlg.m_dCiMin ) && ( dlg.m_dCrMax != dlg.m_dCrMin ) )
{
::WaitForSingleObject( HMutexActive, INFINITE );
parametersActive.m_dCiMax = max( dlg.m_dCiMax, dlg.m_dCiMin );
parametersActive.m_dCiMin = min( dlg.m_dCiMax, dlg.m_dCiMin );
parametersActive.m_dCrMax = max( dlg.m_dCrMax, dlg.m_dCrMin );
parametersActive.m_dCrMin = min( dlg.m_dCrMax, dlg.m_dCrMin );
parametersActive.m_dLMax = dlg.m_dLMaximum;
parametersActive.m_nNMax = dlg.m_nNMax;
parametersActive.m_nPalSize = dlg.m_nPalSize;
parametersActive.m_nColorShift = dlg.m_nColorShift;
::ReleaseMutex( HMutexActive );
}

OnNewParameters(); // Update undo parameter array

// Then redraw the window
Invalidate();
}
}