Solved

Control Arrays

Posted on 2002-07-23
4
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 50 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 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