?
Solved

Control Arrays

Posted on 2002-07-23
4
Medium Priority
?
342 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

764 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