You are here:



QUESTION: Hi again, Bill. Thank you for your patience. ;o) There were too many follow-ups, so AllExperts had me start a new question. I'm somewhat new to VC++, though I'm somewhat competent at Visual Basic. Though I've finished the program that we're working on, I'd like to shorten the code by making an array of the many edit boxes.

I'll start with your first question: Does this mean that when dealing with DoDataExchange that I should 'include' another header file? This might explain the compiler not recognizing the pointer, though there's no mention of a special header file for DoDataExchange in MSDN....
I've tried the line: CDialog::DoDataExchange(pDX); but the compiler still complains that 'pDX' is an "undeclared identifyer"...
I'm placing this test in the middle of the function 'void CTest1Dlg::OnStart'. In my program: when information has been gathered from the user, the start button is clicked and all the edit boxes are filled. So I can't start another function as in MSDN: 'void DoDataExchange(CDataExchange* pDX);' or should I?
OK, I did and tried:
void DoDataExchange(CDataExchange* pDX);
CEdit m_cedit[10];

DDX_Control(pDX, IDC_EDIT_STRT_ALT_00, m_cedit[0]);
DDX_Control(pDX, IDC_EDIT_STRT_ALT_01, m_cedit[1]);
Still the same error that:"pDX is an undeclared identifyer"; not in 'void DoDataExchange(CDataExchange* pDX);' which the compiler passed but in: 'DDX_Control(pDX, IDC_EDIT_STRT_ALT_00, m_cedit[0]);' where it didn't like pDX. Go figure...

Second question: I guess that you want me to right click one of the edit boxes to see if "Add variable" is grayed out. Upon doing so there was no "Add variable" at all, let alone grayed out. When I clicked 'properties' I got the ID names: IDC_EDIT_STRT_ALT_00 through IDC_EDIT_STRT_ALT_19.
I did use the 'ClassView' tab in the workspace window and found all the variable names for the edit boxes with a blue brick next to each one: m_StrtAlt00 through m_StrtAlt19.

I hope that you find this information useful and that reading all this was not just a waste of your time. :o) Thank you for all your help.

ANSWER: Ok.  Getting there...

DoDataExchange is an override. So in your class derived from CDialog i the H, you need:

 virtual void DoDataExchange(CDataExchange* pDX);   // DDX/DDV support

And in the CPP:

void CTestDlg::DoDataExchange(CDataExchange* pDX)
 DDX_Control(pDX, IDC_EDIT1, m_cedit[0]);
 DDX_Control(pDX, IDC_EDIT2, m_cedit[1]);
 DDX_Control(pDX, IDC_EDIT3, m_cedit[2]);
 DDX_Control(pDX, IDC_EDIT4, m_cedit[3]);

About Add variable, I have VC++ 2002 (and use 2003 at work) so you could have later or .NET which doesn't have it.

Try the override above and see how it goes.  What VC++/.NET are you using?


---------- FOLLOW-UP ----------

QUESTION: Hi again, Bill.

I'm lost on your second sentence:
"So in your class derived from CDialog i the H, you need:"
Does that mean in the header or in the header file?
I tried "virtual void DoDataExchange(CDataExchange* pDX);" in the header grouped among the function prototypes and got a complaint from the compiler that "only member functions and bases can be virtual".
I also tried it in the header file and got the same compiler complaint.
Dropping the 'virtual'part of the line, the compiler just went back to "pDX is an undeclared identifier".
I remain at square one. :o(


ANSWER: Hi Neil - hang in there buddy! :)

In the class for the dialog.  You probably have something like:

class MyDialog : class CDialog
 void DoDataExchange(CDataExchange* pDX);

in the H file.  Add the DoDataExchange prototype in this class.

In the CPP, add:

void MyDialog::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_EDIT1, m_cedit[0]);

From the error you got, the prototype was not in the class, or you had virtual on the function definition.

Try this.  The next step we can try if this isn't working is I can create a temp email address so you can send me a CPP and H file and I'll give it a try here and see what's going on.


---------- FOLLOW-UP ----------

QUESTION: Did all you wrote in your note - still "pDX is an undeclared identifier". We're getting closer, I feel.



I'm confused too now, since pDX is declared in the function formal parameter list.  If you have:

void MyDialog::DoDataExchange(CDataExchange* pDX)

It says pDX is not defined?  If it's OK, delete this and add each line back in, one at a time.  Like you, I don't see how there's an error.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.