Link to home
Start Free TrialLog in
Avatar of charles_gilley
charles_gilley

asked on

DDX_Control - valid arguments?

I have a fairly complicated dialog that I need to map/unmap sets of controls.  I didn't want to have 30+ control variables running around, so I thought I would organize things in a structure.  So, in my DataExchange method, after the AFX wrappers, I have:

         DDX_Control(pDX, IDC_A_11_STATIC, m_BankA.cGunType[0].cLabels[0]);
         DDX_Control(pDX, IDC_A_12_STATIC, m_BankA.cGunType[0].cLabels[1]);
         DDX_Control(pDX, IDC_A_13_STATIC, m_BankA.cGunType[0].cLabels[2]);

the above is a code snippet - compiles fine.  The .cLabels[n] reference a custom activeX control.  Looking at this code, I would think that I have something equivalent to :

         DDX_Control(pDX, IDC_A_11_STATIC, m_cLabels[0]);  // example

However, using the structure notion results in an assertion violation, while the array reference does not.

Today's question is - why?  Both code snippets decompose to the same discrete variable location, or so I think...
What am I missing?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

What is missing? - support from the IDE for this second method.  What the DDX tries to do is assign ONE variable to ONE control.  You get the assert as the variable doesn't make sense for the assignment.

What you can do for the DDX routine (IF the control ID's are incremented by one) is have it in a loop

for(int i = 0; i < 3; i++)
  DDX_Control(pDX, IDC_A_11_STATIC+i, m_BankA.cGunType[0].cLabels[i]);
Avatar of charles_gilley
charles_gilley

ASKER

Andy,

  How is your method different from mine other than you are using a loop, and I unrolled mine?
I'm coding this by hand, so I don't care about the IDE at all.  I'm just wondering about the structure
reference of the control.....

Sorry to be dense...
I may not of understood you.
I thought you were attempting a shortcut where you expected the DDX to 'know' how large the array was and automatically assign variables to the controls until the end of the array was reached.

What ASSERT do you get?
Nope - been there, done that, have the t-shirt :).  That's a newbie mfc question, and I'm just about 12" above newbie status... ;)

Here's the real code snippet:

      //{{AFX_DATA_MAP(CDriverboardPropertiesDlg)
      DDX_Control(pDX, IDC_PS_TYPE_STATIC, m_cPowerSupplyStatic);
      DDX_Control(pDX, IDC_TITLE_STATIC, m_cTitleStatic);
      //}}AFX_DATA_MAP


         //DDX_Control(pDX, IDC_BANK_A_GBOX, m_BankA.cGroupBox);

         // Gun 1:

         DDX_Control(pDX, IDC_A1_DEVICE_BTN, m_BankA.cGunType[0].cDeviceTypeBtn);

A couple of notes.  First, the AFX_DATA_MAP is the typical area added by the IDE.  Note the standard single control variable passed into DDX_Control.  Works fine.

Now, after the last comment - this DDX_Control statement is added manually and is misbehaving.  The cDeviceTypeBtn is defined as a control, it all compiles, but when it executes I get an access violation (C0000005) inside of SubclassWindow.  I'm going to do more testing...
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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
I believe so.  I step into the DDX_Exchange code... we make it all the way into the SubclassWindow call and crater at PreSubclassWindow();  Just walked through the execution for a standard single control - looks the same as the other.  

fwiw, I've duplicated this behavior with my controls (custom activeX) and standard CButton controls, so I don't think I have anything weird in this area.

Wait a minute... the address displayed by the debugger in EVC++ says 0x000000 for the function.  Hmmmm...
Okay, I've got a class problem / inheritance issue.  When I create a structure and possibly an array, I've got a null pointer around for this virtual function.
Whoops, forgot about this one.  Apologies to one and all... Andy, thanks for your help and suggestions. points to you...