Solved

DDX_Control - valid arguments?

Posted on 2004-10-26
1,062 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
Question by:charles_gilley
    8 Comments
     
    LVL 43

    Expert Comment

    by:AndyAinscow
    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
    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 43

    Expert Comment

    by:AndyAinscow
    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
     

    Author Comment

    by:charles_gilley
    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 43

    Accepted Solution

    by:
    Is m_BankA.cGunType[0].cDeviceTypeBtn valid?
    Step into the DDX_Control function and find the line asserting.
    0
     

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
    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.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    933 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