Errors, bugs, questions - page 1455

 

Here's the script.

Created an object. Assigned text.

Recognising the text itself and the size.

Why is the text itself recognized, but the size is not?

Files:
prob.mq4  1 kb
 
Vasyl Nosal:

Here's the script.

Created an object. Assigned text.

Recognising the text itself and the size.

Why does it recognize the text but not the size?

I just checked.

Even the colour comes back correctly.

Why isn't the size? Is this some kind of taboo?

Files:
prob.mq4  1 kb
 
Vasyl Nosal:

I just checked.

Even the colour returns correctly.

Why isn't the size? Is this some kind of taboo?

Until the text label is rendered, the size is unknown. What's not clear here?
 
Vasyl Nosal:

I just checked.

Even the colour returns correctly.

Why isn't the size? Is that some kind of taboo?

Because the object has no time to render, you want too much...

string name="probe";
/////
void OnStart()
  {
   func();
   func();

   ObjectDelete(name);

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void func()
  {
   ObjectCreate(0,name,OBJ_LABEL,0,0,0);
   ObjectSetString(0,name,OBJPROP_TEXT,name);

   Sleep(500);

   string text=ObjectGetString(0,name,OBJPROP_TEXT);

   int text_sizeX=int(ObjectGetInteger(0,name,OBJPROP_XSIZE));
   Alert(text," ",text_sizeX);

  }
//+------------------------------------------------------------------+
 

Opera browser

Opera 34.0

Do more on the web

Version information

Version:34.0.2036.25- Updated version of Opera is used
Update Channel:Stable
System:Windows 10 64-bit (WoW64)

Browser ID

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36 OPR/34.0.2036.25

When inserting a new message using SRC, the SRC text disappears.

When updating using/inserting SRC it's fine.

 
Vladimir Pastushak:

because the object doesn't have time to render, you want too much...

That's cool.

Now please help me to implement this in an indicator and make it work without ticks (on weekends).

 
Slawa:
As long as the text label is not rendered, the size is unknown. What is not clear here?

Do you have a solution to this issue in an indicator, without ticks?

And I've said it before. It's strange that you can get the text itself without rendering but not the size.

 
Vasyl Nosal:

That's cool.

Now please help me to implement it in an indicator and make it work without ticks (on weekends).

---

//+------------------------------------------------------------------+
//|                                                        proba.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

string name="probe";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1 /*переодичность в секундах*/); // 
                                                  // или
//bool  EventSetMillisecondTimer( 
//int  milliseconds      // количество миллисекунд 
//);
   ObjectCreate(0,name,OBJ_LABEL,0,0,0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ObjectSetString(0,name,OBJPROP_TEXT,name);
   string text=ObjectGetString(0,name,OBJPROP_TEXT);
   int text_sizeX=int(ObjectGetInteger(0,name,OBJPROP_XSIZE));
   Alert(text," ",text_sizeX);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(name);
   EventKillTimer();
  }
//+------------------------------------------------------------------+
 
Vladimir Pastushak:

---

Thank you. But it's cumbersome to know the size of the text, to put it mildly.

Why is it possible to find out the text size without rendering but not the text size?

 
Vasyl Nosal:

Thank you. But it's cumbersome to know the size of the text, to put it mildly.

Why can we know the text itself without rendering but not its size?

Perhaps the text to be rendered is stored in a variable from which we retrieve it and you have to create an object of thousands of pixels to create the text.

And the code I gave you is just an example of a runtime implementation.