Solved

Dialog controls / member variables

Posted on 1998-11-13
5
224 Views
Last Modified: 2010-04-02
I currently use the classwizard to add menber variables to the different controls I have within a dialog box. For example I would create a member variable like let's say "m_HkdBid1" which would be linked to an edit box.

Now the problem I have is that in some dialog boxes, I have a lot of edit boxes which I have to initialize one by one and it is not very efficient. I would like to declare my control name and member variables names as part as an array so that I can later use a fast loop to initialize them. But at the moment class wizard would not let me name a member variable something like m_HkdBid[1] (it seems the square brackets are illegal characters in this case). Same question with the name of the controls. So in short, how can I declare controls' name and member variables names which are part of an array of data ?
0
Comment
Question by:decornez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:dinom
ID: 1177848
Do you think you could forego using classwizard by adding code by hand.  That is add an array member variable (i.e. an array of CStirngs) then place approriate loops around the macros that classwizard would have generated (i.e. validation and initialization).  Examine how class wizard goes about adding the class member, I think it just adds the class member and couple of macros into the constructor for data initialization and a few macros into the data validation routine, then reproduce what classwizard would have done but with your loops and an array.  I can't really see why this wouldn't work.  Again, your problem seems to be that your not too sure exactly what classwizard does when you add a control and associate it with a class member.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1177849
You can declare an array of pointers say
CString *values[10];
CEdit *controls[10];
Then in the constructor, make each pointer point to the appropraite members.
values[0]=&m_editvalue1;
controls[0]=&m_editctrl1;
And the use the array members to manipulate data and controls.
Thanks and best of luck.
pagladasu
0
 

Author Comment

by:decornez
ID: 1177850
pagladasu,

thanks for proposed answer. Unfortunately, I still cannot loop to initialize my variables as we still have m_editvalue1, m_editvalue2...etc

dinom,

I have tried this approach. I can replicate what the viewer does manually and declaring arrays of variables instead of a group of single variables, but After I do that, although the code runs, my viewer goes bezerk every time I try to work on the design of my dialog, and I cannot anything without getting loads of warning messages.
So basically, I do not think that it is feasible given the way MS VC++ 5 is build.
I wonder if version 6 can cater for this type of situation.

Anyway, thanks to both of you for your time and effort.
A.
0
 

Accepted Solution

by:
McCreary earned 30 total points
ID: 1177851
Put something like this in OnInitDialog()
#define NUM_VALUES 3
static UNIT idc[NUM_VALUES] = {IDC_CONTROL1, IDC_CONTROL2, IDC_CONTROL3};
char text[128];

for ( short i=0; i<NUM_VALUES)
{
    sprintf(value, "%d", value[i]);   // or whereever your value comes from
    GetDlgItem(idc[i])->SetWindowText(text);
}

If the static arrary idc is outside the scope of the OnInitDialog, you can use the inverse code to put the text from the controls back into the values in OnOK()


0
 

Author Comment

by:decornez
ID: 1177852
McCreary,

Thanks for your answer. By actually making the controls part of an array and then looping through, it allows me to initialize all the data rather fast.

So well done, the points are yours.

Rgds,
A.
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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 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