mql5 ObjectGetString(): buggy or not? (video attached) OBJ_EDIT / OBJPROP_TEXT

 

Hi everyone!

For some reason, if I input a string in a box on the Chart using "ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))"
and retrieve it in a global variable named "string_value" with "ObjectGetString(0, "Input_Text",OBJPROP_TEXT,0,string_value)"
it only saves it with a delay, while on the contrary, I would like my input to be taken into account as soon as
the "Enter" key on the keyboard is pressed, after the input.


I have spent hours trying to understand why, I have not found a solution and God knows how
I am persistent. I have searched the forums and Google with no luck.

If you can help me, I would be grateful... This is a bug, isn't it?

I have attached a video (in the zip file) - latest MetaEditor 5 build 3270).

#property indicator_chart_window

string string_value;

int OnInit()
  {
   EditCreate(14,"Input_Text", 200, 300, 120, 80, "", ALIGN_CENTER);
   return INIT_SUCCEEDED;
  }

int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[])
  {
   //Sleep(5000);
   Print("1 String Value : ",string_value);
   return rates_total;
  }

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="Input_Text")
     {
      ObjectGetString(0,"Input_Text",OBJPROP_TEXT,0,string_value);
      Print("2 String Value : ",string_value);
     }
   else
      if(id==CHARTEVENT_OBJECT_ENDEDIT)
        {
         Print("The text in the Edit field of the object with name ",sparam," has been changed");
         Print("3 String Value : ",string_value);
        }
  }

bool EditCreate(const int              font_size=14,             // font size
                const string           name="Edit",              // object name
                const int              x=0,                      // X coordinate
                const int              y=0,                      // Y coordinate
                const int              width=50,                 // width
                const int              height=18,                // height
                const string           text="Text",              // text
                const ENUM_ALIGN_MODE  align=ALIGN_RIGHT,        // alignment type

                const long             chart_ID=0,               // chart's ID
                const int              sub_window=0,             // subwindow index
                const string           font="Arial",             // font
                const bool             read_only=false,          // ability to edit
                const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                const color            clr=clrBlack,             // text color
                const color            back_clr=clrWhite,        // background color
                const color            border_clr=clrBlack,      // border color
                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
  {
   if(!ObjectFind(chart_ID,name)) // If successful the function returns the number of the subwindow (0 means the main window of the chart)
     {
      ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); // only update the text
      return true;
     }

   ResetLastError();
   if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0)) //--- create edit field
     {
      Print(__FUNCTION__, ": failed to create \"Edit\" object! Error code = ",GetLastError());
      return false;
     }

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); //--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); //--- set object coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); //--- set object size
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); //--- set the text
   ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align); //--- set the type of text alignment in the object

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); //--- set text font
   ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only); //--- enable (true) or cancel (false) read-only mode
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); //--- set the chart's corner, relative to which object coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set text color
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); //--- set background color
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); //--- set border color
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); //--- enable (true) or disable (false) the mode of moving the label by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- set the priority for receiving the event of a mouse click in the chart
   return(true);
  }
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
input_box.zip  7164 kb
 
Where is the indicator file?
 
Vladimir Karputov #:
Where is the indicator file?

updated - thanks

 

You forgot to poll an element when you stopped editing:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="Input_Text")
     {
      ObjectGetString(0,"Input_Text",OBJPROP_TEXT,0,string_value);
      Print("2 String Value : ",string_value);
     }
   else
      if(id==CHARTEVENT_OBJECT_ENDEDIT)
        {
         ObjectGetString(0,"Input_Text",OBJPROP_TEXT,0,string_value);
         Print("The text in the Edit field of the object with name ",sparam," has been changed");
         Print("3 String Value : ",string_value);
        }
  }
 
Fernando Carreiro #:

The code that the OP has posted and attached as a file "_input_box.mq5" is the the indicator in question. Is that what you are asking?

 
Vladimir Karputov #:
Thanks! I only saw it after I posted. That is why I then deleted my post, but you answered to quickly for me.
 
Fernando Carreiro # :
Thanks! I only saw it after I posted. That is why I then deleted my post, but you answered to quickly for me.

That's why you need to relax on the weekend :)

That's it, I turn off the computer!

 

Thanks very much Vladimir!!!!

I love you :-)))))))))

Reason: