RadioGroup with RadioButtons (Pointers)

 

I'd like to create a RadioGroup with some RadioButtons:

With the "AddItem" function i can add radiobuttons into the RadioGroup.

I use the mql4 controls classes. I know there is already an existing Radiogroup file but It's not for my use and I need to create my own.

So, if I udnerstand right, I need to use pointers right? (I really do hate pointers and won't get along with them-.-)

This was my attempt:

class CRadioGroup2 : public CWndContainer
{
   private:
      //--- dependent controls
      CPanel            m_background;
      CRadioButton*     m_button[];         // array of the row objects
//********************************************************************
//* Create a control                                                                                *
//********************************************************************
bool CRadioGroup2::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{  
   m_maxItems = (int)floor((y2-y1)/m_itemHeight);                                         //Determine the number of visible rows
   if(m_maxItems < 1)                                                { return(false); }   //Check the number of visible buttons

   if(!CWndContainer::Create(chart, name, subwin ,x1, y1, x2, y2))   { return(false); }   //Call method of the parent class
   if(!m_background.Create(chart, name, subwin, x1, y1, x2, y2))     { return(false); }
   if(!m_background.ColorBackground(CONTROLS_RADIOGROUP_COLOR_BG))   { return(false); }   //BG Color of background
   //if(!m_background.ColorBorder(CONTROLS_RADIOGROUP_COLOR_BORDER))   { return(false); } //Border color of background
   if(!m_background.ColorBorder(clrBlack))                           { return(false); }
   if(!Add(m_background))                                            { return(false); }
   //--- succeed
   return(true);
}
//********************************************************************
//* Add item (row)                                                                                     *
//********************************************************************
bool CRadioGroup2::AddItem(const string text, const long value)
{
   
   if(Size()+1 > m_maxItems)                 { return(false); }         //Check Max Items
   if(value!=0 && !ValueCheck(value))        { return(false); }         //--- check value
   //--- add
   if(!CreateButton(text))                    { return(false); }
   ArrayResize(m_values, Size());
   m_values[Size()-1] = value;
   if(Size() == 1)   { Select(0); }

   return(Redraw());
}
//********************************************************************
//* Create Radio Button                                                                                   *
//********************************************************************
bool CRadioGroup2::CreateButton(const string text)
{
   ArrayResize(m_button, Size()+1);
   int index = Size() - 1;
    m_button[index] = new CRadioButton;         //Creating Pointer with new operator
   //--- calculate coordinates
   int x1=CONTROLS_BORDER_WIDTH;
   int x2=Width()-CONTROLS_BORDER_WIDTH;
   int y1=CONTROLS_BORDER_WIDTH + m_itemHeight*index;
   int y2=y1+m_itemHeight;
   //--- create
   if(!m_button[index].Create(m_chart_id, m_name+"Button"+IntegerToString(index), m_subwin, x1, y1, x2, y2))   { return(false); }
   if(!m_button[index].Text(text))  { return(false); }
   if(!Add(m_button[index]))  { return(false); }
   //---
   return(true);
}
//********************************************************************
//* Destroy                                                                                          *
//********************************************************************
void CRadioGroup2::Destroy(const int reason=0)
{  
   CWndContainer::Destroy(reason);
   for(int i = 0; i < Size(); i ++)
   {
      if(CheckPointer(m_button[i])!=POINTER_INVALID) { delete(m_button[i]); }
      else { Print(LOG, " Couldn't delete button[",i,"], ", ErrorMsg()); }
   }
   
   ArrayFree(m_button); 
}


Hope someone who has experience with these pointers can help me out...
No joke, already got a headache from this xD

 

The program works, until I change the timeframe.


First Ini:     After I change the TF: 

 

Okey Problem solved.

I did it without pointers. I thought I need pointers for object arrays, but it worked without :)

CRadioButton      m_button[];         // array of the row objects
void CRadioGroup2::Destroy(const int reason=0)
{  
   CWndContainer::Destroy(reason);
   
   ArrayFree(m_button);
}
bool CRadioGroup2::CreateButton(const string text)
{
   ArrayResize(m_button, Total()+1);
   int index = Total() - 1;
   //--- calculate coordinates
   int x1 = CONTROLS_BORDER_WIDTH;
   int x2 = Width() - CONTROLS_BORDER_WIDTH;
   int y1 = CONTROLS_BORDER_WIDTH + m_itemHeight*index;
   int y2 = y1 + m_itemHeight;
   //--- create
   if(!m_button[index].Create(m_chart_id, m_name+"Button"+IntegerToString(index), m_subwin, x1, y1, x2, y2))   { return(false); }
   if(!m_button[index].Text(text))                                                                             { return(false); }
   if(!Add(m_button[index]))                                                                                   { return(false); }
   //--- succeed
   return(true);
}