X_Size of CChartObjectLabel will be zero(0) after Description, is there any solutiuons?

 
m_LabelInfo is object of CChartObjectLabel
   m_LabelInfo.Color(clrRed);    m_LabelInfo.FontSize(28);    m_LabelInfo.Description("Information");    Print(m_LabelInfo.X_Size()); // The value is 0, why?
m_LabelInfo.X_Size() will be set to zero(0) after calling Description(). I even tried to call ChartRedraw before get X_Size, it still remains 0. But if I mouse click the information, the value will be correct. Why this happen and what is the solution to get the correct value? 
 

You can always use the old skool method.

For a label i did not see any: 

   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); 

Just X and Y Distance.

// Functions:
//- LabelCreate()
//- LabelMove()
//- LabelChangeCorner()
//- LabelTextChange()
//- LabelDelete()
 
//+------------------------------------------------------------------+ 
//| Create a text label                                              | 
//+------------------------------------------------------------------+ 
bool LabelCreate(const long              chart_ID=0,               // chart's ID 
                 const string            name="Label",             // label name 
                 const int               sub_window=0,             // subwindow index 
                 const int               x=0,                      // X coordinate 
                 const int               y=0,                      // Y coordinate 
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring 
                 const string            text="Label",             // text 
                 const string            font="Arial",             // font 
                 const int               font_size=10,             // font size 
                 const color             clr=clrRed,               // color 
                 const double            angle=0.0,                // text slope 
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type 
                 const bool              back=false,               // in the background 
                 const bool              selection=false,          // highlight to move 
                 const bool              hidden=true,              // hidden in the object list 
                 const long              z_order=0)                // priority for mouse click 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- create a text label 
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create text label! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set label coordinates 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
//--- set the text 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Move the text label                                              | 
//+------------------------------------------------------------------+ 
bool LabelMove(const long   chart_ID=0,   // chart's ID 
               const string name="Label", // label name 
               const int    x=0,          // X coordinate 
               const int    y=0)          // Y coordinate 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- move the text label 
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x)) 
     { 
      Print(__FUNCTION__, 
            ": failed to move X coordinate of the label! Error code = ",GetLastError()); 
      return(false); 
     } 
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y)) 
     { 
      Print(__FUNCTION__, 
            ": failed to move Y coordinate of the label! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Change corner of the chart for binding the label                 | 
//+------------------------------------------------------------------+ 
bool LabelChangeCorner(const long             chart_ID=0,               // chart's ID 
                       const string           name="Label",             // label name 
                       const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER) // chart corner for anchoring 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- change anchor corner 
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner)) 
     { 
      Print(__FUNCTION__, 
            ": failed to change the anchor corner! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Change the label text                                            | 
//+------------------------------------------------------------------+ 
bool LabelTextChange(const long   chart_ID=0,   // chart's ID 
                     const string name="Label", // object name 
                     const string text="Text")  // text 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- change object text 
   if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text)) 
     { 
      Print(__FUNCTION__, 
            ": failed to change the text! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
//| Delete a text label                                              | 
//+------------------------------------------------------------------+ 
bool LabelDelete(const long   chart_ID=0,   // chart's ID 
                 const string name="Label") // label name 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- delete the label 
   if(!ObjectDelete(chart_ID,name)) 
     { 
      Print(__FUNCTION__, 
            ": failed to delete a text label! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+ 
 
Marco vd Heijden:

You can always use the old skool method.

For a label i did not see any: 

Just X and Y Distance.

Finally, I get correct value of X_Size() after Sleep(100). It's amazing...........

 
I have the same issue. But I develop indicator instead of expert adviser. It's prohibited to use Sleep function at indicators. It's possible to use Timer in indicators and make calculation in this function. I'm very sad about this bug. I was not able to find different solution(.
 
Nomadmain:
I have the same issue. But I develop indicator instead of expert adviser. It's prohibited to use Sleep function at indicators. It's possible to use Timer in indicators and make calculation in this function. I'm very sad about this bug. I was not able to find different solution(.
There is no bug, it's how it is working. If you want to know the size in pixels of a text, you have to use TextGetSize().
 
Alain Verleyen:
There is no bug, it's how it is working. If you want to know the size in pixels of a text, you have to use TextGetSize().

If it's not a bug then It's a very bad interface.

How do you think is it normal when I have to sleep or use Timer to get real size of recently changed text value in CChartObjectLabel object?

chartObjectLabel.SetString(OBJPROP_TEXT, "New text");
chartObjectLabel.Y_Size(); // Returns 0 because of change text value
Sleep(100);
chartObjectLabel.Y_Size(); // Returns correct value

In indicator it even worse.


I hop (I believe) it's a bug. Because it's very not useful interface. My code looks like spaghetti because of this.

 
Alexander Nomad:

If it's not a bug then It's a very bad interface.

How do you think is it normal when I have to sleep or use Timer to get real size of recently changed text value in CChartObjectLabel object?

In indicator it even worse.


I hop (I believe) it's a bug. Because it's very not useful interface. My code looks like spaghetti because of this.

Very bad interface or very bad coder.

I said you to use TextGetSize().

 
Alexander Nomad:

If it's not a bug then It's a very bad interface.

How do you think is it normal when I have to sleep or use Timer to get real size of recently changed text value in CChartObjectLabel object?

In indicator it even worse.


I hop (I believe) it's a bug. Because it's very not useful interface. My code looks like spaghetti because of this.

Thanks to Alain Verleyen for tips  to use TextGetSize.

This code helps to get size of text object instantly 


bool getTextObjectTextSize(const CChartObjectLabel& object, uint& width, uint& height) { //https://www.mql5.com/en/forum/35582 if (!TextSetFont(object.Font(), -object.FontSize() * 10)) { return false; } if (!TextGetSize(object.GetString(OBJPROP_TEXT), width, height)) { return false; } return true; }


the size of text object label
the size of text object label
  • 2014.08.19
  • www.mql5.com
Hi, if I create an object text label, how can I get the size (length) of that text in pixels. It similars like TextGetSize function...
 
Alain Verleyen:

Very bad interface or very bad coder.

I said you to use TextGetSize().

Yes, I'm very bad coder. The idea to use magic numbers -object.FontSize() * 10 from this article https://www.mql5.com/en/forum/35582 is very good design of making interfaces...)

the size of text object label
the size of text object label
  • 2014.08.19
  • www.mql5.com
Hi, if I create an object text label, how can I get the size (length) of that text in pixels. It similars like TextGetSize function...
Reason: