?
Solved

Control Arrays

Posted on 2002-07-23
4
Medium Priority
?
358 Views
Last Modified: 2008-03-17
I've just started using MS VC++ to write a bit of software and am having a few problems creating control arrays.

I've set it up so that a control array is initialised and then each control has a member variable as an element in the array. This works and compiles fine however the class wizard refuses to open now. I've deleted the .clw file but it still brings up an error about the lines declaring the control arrays.

----------------------------------------------------------
The header file:
...
// Dialog Data
     //{{AFX_DATA(TestDlg)
     enum { IDD = IDD_TEST_DIALOG };

     CButton               m_ctrl_button_browse[7];
...


The cpp file:
...
void TestDlg::DoDataExchange(CDataExchange* pDX)
{
     CDialog::DoDataExchange(pDX);
     //{{AFX_DATA_MAP(testDlg)
     DDX_Control(pDX,           IDC_BUTTON_BROWSE_0,               m_ctrl_button_browse[0]);
     DDX_Control(pDX,           IDC_BUTTON_BROWSE_1,               m_ctrl_button_browse[1]);
     DDX_Control(pDX,           IDC_BUTTON_BROWSE_2,               m_ctrl_button_browse[2]);
...


Error:
Parsing error: Expected ";".
Input Line: "CButton               m_ctrl_button_browse[7];"

----------------------------------------------------------

Have I done something wrong?

Thanks in advance,

Steve
0
Comment
Question by:elstcb
4 Comments
 
LVL 8

Expert Comment

by:fl0yd
ID: 7172471
No, it is the class wizard that is messing things up if it isn't fed with the EXACT syntax it is expecting. While your code is perfectly c++-compliant code and thus also compiles, the ClassWizard still isn't grown up yet. You are facing two solutions: either work around it by not using arrays. This will probably result in messy code and will obscure why you used an array in the first place if someone else is trying to read the code (it could be you half a year from now that is wondering why). Or you could not use the ClassWizard altogether in the future and do everything manually. There is a good book out there that explains what all those MFC macros do and how to do MFC coding without the ClassWizard. Take a look at it here: http://www.amazon.com/exec/obidos/ASIN/1572316950/
0
 
LVL 4

Accepted Solution

by:
mblat earned 200 total points
ID: 7172484
Actually one way to get around it would be to put "offending" DDX_*** macros OUTSIDE

//{{AFX_DATA_MAP(testDlg)
.....
//}}AFX_DATA_MAP

block.....

Class wizard will work, but not with the vars. defined outside....
0
 
LVL 30

Expert Comment

by:Axter
ID: 7172689
Just to add to mblat comment, here's an example:
In header file (*.h)

// Dialog Data
     //{{AFX_DATA(CTestDlg)
     enum { IDD = IDD_TEST_DIALOG };
     //}}AFX_DATA
     CButton     m_ctrl_button_browse[3];  //Put this out side of AFX_DATA control blocks


In source file (*.cpp)
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
     CDialog::DoDataExchange(pDX);
     //{{AFX_DATA_MAP(CTestDlg)
     //}}AFX_DATA_MAP
     DDX_Control(pDX, IDC_BUTTON1, m_ctrl_button_browse[0]);
     DDX_Control(pDX, IDC_BUTTON2, m_ctrl_button_browse[1]);
     DDX_Control(pDX, IDC_BUTTON3, m_ctrl_button_browse[2]);
     
}
0
 
LVL 2

Author Comment

by:elstcb
ID: 7173756
Thank you!

Whilst not an ideal solution it does fit the purpose, I'd rather have the control arrays and them not show up in the class wizard than not use control arrays or have no class wizard at all!

Do I take it that MS have fixed this problem in C#? I hope so, you'd think they'd have seen it coming with it being so easy to create control arrays in VB!

Thanks again.

Steve
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

864 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