Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to DoDataExchange in the MainFrame of a SDI?

94 views
Skip to first unread message

Yves

unread,
Mar 7, 2000, 3:00:00 AM3/7/00
to
I've got this problem since the beginning of the development of my SDIapp.
I need to fill and get results from CEdits I've put in dialogs that I
attached to CMainframe. When I try to add DoDataExchange to CEdits from
m_myDialogBar, i get "Debug Assertion Failed" ! Where's the mistake here?


in MainFrm.h :


class CMainFrame : public FrameWnd
{...

protected:
CString m_strmyString;
CDialogBar m_myDialogBar;

virtual void DoDataExchange( CDataExchange * pDX);
...}

And in MainFrm.cpp:

int CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...

m_myDialogBar.Create(this, IDD_DIALOGBAR /*the associated Dialog*/,
CBRS_TOP|CBRS_TOOLTIPS|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, IDD_DIALOGBAR)

...
}

void CMainFrame::DoDataExchange(CDataExchange*pDX)
{
CMainFrame::DoDataExchange (pDX);
DDX_Text(pDX,IDC_MYEDIT/* the associated edit box for m_strmyString*/
,m_strmyString);
}

Thanks in advance

Yves.

Dave Hamilton

unread,
Mar 7, 2000, 3:00:00 AM3/7/00
to
In your DoDataExchange call

CDialog::DoDataExchange(pDX); before your DDX routines instead of
CMainFrame's

Dave

David Wilkinson

unread,
Mar 7, 2000, 3:00:00 AM3/7/00
to
Yves:

I don't use CDialogBar, but don't you need to have a derived CDialogBar class
and put the data exchange there? The edits you are talking about are child
controls of the dialog bar, not the mainframe, no?

Burt when you get "Debug assertion failed" you need to go into the debugger
and see what the ASSERT was related to. ASSERT's are your friend, because they
are about to tell you what is wrong with your code.

HTH,

David Wilkinson

=============================

Joseph M. Newcomer

unread,
Mar 8, 2000, 3:00:00 AM3/8/00
to
Not terribly surprising. DoDataExchange applies only if you have all
the appropriate bindings done to the controls, and unless the values
are direct child controls of CMainFrame, you don't have this ability.
You can't really (or shouldn't) bind control handles of child controls
of some dialog to variables in some other window. This is terrible
programming practice, if it could be made to work at all.

This is one of the few places where UpdateData, which is otherwise
misused, is exactly the right thing to do. Just use ClassWizard in
your dialogs to create the DDXs for value variables. When you want the
values from a dialog, send a user-defined message to the dialog (we're
presumably talking modeless dialogs, like dialog bars, here), telling
it to call UpdateData with the Boolean that causes control values to
be snapped back to the member variables. When this SendMessage
returns, you can simply reach into the dialog's public variables and
retrieve what you want.

My own preference is to send a message to the dialog that retrieves
the value I want, and avoid UpdateData entirely, but if you have a lot
of controls this would be clumsy. Most of my toolbox-like modeless
dialogs have only a couple parameters they are managing.

But get rid of that DoDataExchange in the mainframe. It is
meaningless, harmful, and the wrong approach to the problem.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm

0 new messages