Link to home
Start Free TrialLog in
Avatar of elstcb
elstcb

asked on

Control Arrays

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
Avatar of fl0yd
fl0yd

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/
ASKER CERTIFIED SOLUTION
Avatar of mblat
mblat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Axter
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]);
     
}
Avatar of elstcb

ASKER

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