Button in array

 

Hi,

i have problem with button array. I'm not able to fill the object field with the buttons.

Is somebody to help me? 


#include <Controls\Button.mqh>

class Panel : public CAppDialog

{
private:
   CButton           m_BtnSymbol1, m_BtnBymbol2;

public:
                     Panel(void);
                    ~Panel(void) {};
        
   virtual bool      Create(const long chart, const string name, const int subwin, const int x1, const int y1);

   private:     


   virtual bool      ButtonCreate    (CButton&    Btn, int X1, int Y1, int X2, int Y2, string Name, string Text);




//+--------+
//| Button |
//+--------+
bool Panel::ButtonCreate(CButton &Btn, int X1, int Y1, int X2, int Y2, string Name, string Text)
{
   if (!Btn.Create(m_chart_id, m_name + Name, m_subwin, X1, Y1, X2, Y2))       return(false);
   if (!Add(Btn))                                                              return(false);
   if (!Btn.Text(Text))                                                        return(false);

   return(true);
}


bool Panel::CreateObjects()
{

   if (!ButtonCreate(m_BtnSymbols1, 1 ,1 , 10, 10 , "m_BtnSymbol1", "Symbol1"))                  return(false);
   if (!ButtonCreate(m_BtnSymbols2, 15 ,15 25, 25 , "m_BtnSymbol2", "Symbol2"))                  return(false);


//There is problem
//Cteated one dimension array with two index => OK

 CButton  button[2];

//I need feel this array, but There is problem   Log:'=' - not allowed for objects with protected members or inheritance

          button[0] = m_BtnSymbol1;   
          button[1] = m_BtnSymbol2;


        
        
      InitObjects();
   

   return(true);                
 }


Files:
 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. CButton  button[2];
              button[1] = m_BtnSymbol2;   
              button[2] = m_BtnSymbol2;
    An array with two elements has indexes zero and one.
 
This won't work. OP, you need to use pointers instead. 
CButton  *button[2];
button[0] = &m_BtnSymbol1;   
button[1] = &m_BtnSymbol2;
 
nicholishen:This won't work. OP, you need to use pointers instead. 

Unfortunately, it did not help. 

     CButton  *button[2];

      button[0] = &m_BtnSymbol1;   
      button[1] = &m_BtnSymbol2;

After compilation he writes this:

'm_BtnSymbol1' - undeclared identifier

'&' - illegal operation use Panel.mql

'm_BtnSymbol1' - class type expected

'=' - type mismatch

Any other idea?
 
Robo779:

Unfortunately, it did not help. 

After compilation he writes this:

'm_BtnSymbol1' - undeclared identifier

'&' - illegal operation use Panel.mql

'm_BtnSymbol1' - class type expected

'=' - type mismatch

Any other idea?


#include <Controls\Button.mqh>

class Panel : public CAppDialog

{
private:
   CButton           *m_BtnSymbol1, *m_BtnBymbol2;

public:
                     Panel(void);
                    ~Panel(void) {};
        
   virtual bool      Create(const long chart, const string name, const int subwin, const int x1, const int y1);

   private:     


   virtual bool      ButtonCreate    (CButton&    Btn, int X1, int Y1, int X2, int Y2, string Name, string Text);




//+--------+
//| Button |
//+--------+
bool Panel::ButtonCreate(CButton &Btn, int X1, int Y1, int X2, int Y2, string Name, string Text)
{
   if (!Btn.Create(m_chart_id, m_name + Name, m_subwin, X1, Y1, X2, Y2))       return(false);
   if (!Add(Btn))                                                              return(false);
   if (!Btn.Text(Text))                                                        return(false);

   return(true);
}


bool Panel::CreateObjects()
{

   if (!ButtonCreate(m_BtnSymbols1, 1 ,1 , 10, 10 , "m_BtnSymbol1", "Symbol1"))                  return(false);
   if (!ButtonCreate(m_BtnSymbols2, 15 ,15 25, 25 , "m_BtnSymbol2", "Symbol2"))                  return(false);


//There is problem
//Cteated one dimension array with two index => OK

 CButton  *button[2];

//I need feel this array, but There is problem   Log:'=' - not allowed for objects with protected members or inheritance

          button[0] = m_BtnSymbol1;   
          button[1] = m_BtnSymbol2;


        
        
      InitObjects();
   

   return(true);                
 }
Reason: