Solved

Control Arrays

Posted on 2002-07-23
4
323 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 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now