Concatenate name of instance object Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Concatenate name of instance object

Post by mxoliveira73 »

Hi, I have one doubt and give some idea what is my problem.

I need create 70 wxChoice; Then, I have a idea to do something like this ( it's only a idea):
first, of corse, is it possible generate them dynamically, in Runtime?

Code: Select all

for (int i = 1, i < 70, i++)
{ wxChoice*  Choice(i) = new wxChoice(panel, ID_Choice(i), wxDefaultPosition, wxDefaultSize);
    Choice(i)->Append(wxT("one"));
    Choice(i)->Append(wxT("two"));
}

// or this:

for (int i = 1, i < 70, i++)
{
wxArrayString strings(i);
strings(i).Add(wxT(“One”));
strings(i).Add(wxT(“Two”));
wxChoice*  Choice(i) = new wxChoice(panel, ID_Choice(i), wxDefaultPosition, wxDefaultSize, strings(i));
}
Last edited by mxoliveira73 on Sun Jun 02, 2019 5:36 pm, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Concatenate name of instance object

Post by doublemax »

The syntax of your code is wrong, but in principle it's possible.

Code: Select all

  #define NUM_CHOICES 70

  // in real code these two arrays should be member variables,
  // so you can access then later
  // under normal circumstances you won't need the id-array
  wxChoice *choices_array[NUM_CHOICES];
  int choice_ids[NUM_CHOICES];

  for( int i=0; i<NUM_CHOICES; i++ )
  {
    wxChoice *choice = new wxChoice(panel, wxID_ANY);
    choices_array[i] = choice;
    choice_ids[i] = choice->GetId();
  }
Use the source, Luke!
mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: Concatenate name of instance object

Post by mxoliveira73 »

Thanks! Doublemax
Post Reply