?
Solved

DDX_Control - valid arguments?

Posted on 2004-10-26
9
Medium Priority
?
1,114 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:charles_gilley
  • 5
  • 3
8 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12419015
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]);
0
 

Author Comment

by:charles_gilley
ID: 12420670
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...
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 12421471
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?
0
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!

 

Author Comment

by:charles_gilley
ID: 12422788
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...
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 450 total points
ID: 12423198
Is m_BankA.cGunType[0].cDeviceTypeBtn valid?
Step into the DDX_Control function and find the line asserting.
0
 

Author Comment

by:charles_gilley
ID: 12423427
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...
0
 

Author Comment

by:charles_gilley
ID: 12423458
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.
0
 

Author Comment

by:charles_gilley
ID: 12816341
Whoops, forgot about this one.  Apologies to one and all... Andy, thanks for your help and suggestions. points to you...
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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

616 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