Errors, bugs, questions - page 1149

 
Contender:

Otherwise:

string var1[1][2] = {{"dfdffd", "dfdfdfd"}}

?

thanks....question removed.
 

Greetings respected community.

I couldn't find it on the website, and I haven't understood it myself for half a day, why this code writes an error. Please tell me if you can.

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
   string nameObject="testObject";
   ChartRedraw(0);
   ResetLastError();
   if(ObjectFind(0,nameObject)>=0){
      if(!ObjectDelete(0,nameObject)){
         if(_LastError>0){
            Print("1 Ошибка №",_LastError);
            ResetLastError();
         }
      }
   }
   ChartRedraw(0);
   if(_LastError>0){
      Print("2 Ошибка №",_LastError); // Тут ошибка №4202 <Графический объект не найден>
      ResetLastError();
   }
   if(!ObjectCreate(0,nameObject,OBJ_LABEL,0,0,0)){
      if(_LastError>0){
         Print("3 Ошибка №",_LastError);
         ResetLastError();
      }
   }else{
      ObjectSetInteger(0,nameObject,OBJPROP_CORNER,1);
   }
   if(_LastError>0){
      Print("4 Ошибка №",_LastError);
      ResetLastError();
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
svds75:

Greetings respected community.

I couldn't find it on the website, and I haven't understood it myself for half a day, why this code writes an error. Please tell me if you can.

Why delete the object?
 
sergeev:
why delete an object?
The program is actually more complex. I have already simplified it out of all proportion to see what the problem is. But I haven't figured it out.
 
svds75:
The programme is actually more complex. I have already simplified it out of all proportion to see what the problem is. But I still don't understand it.
Try to understand why there is only one message and not every tick, then there will be no questions.
 
svds75:
Actually the program is more complex. I've already simplified it out of all proportion to see what the problem is. But I still don't understand it.

judging by the style of the code, it can still be simplified.

Maybe I got confused in the if/else?

 
svds75:

Greetings respected community.

I couldn't find it on the website, and I haven't understood it myself for half a day, why this code writes an error. Please tell me if you can.

The code is better readable in this layout and the error is immediately visible:

//---
   string nameObject="testObject";
   ChartRedraw(0);
   ResetLastError();
   if(ObjectFind(0,nameObject)>=0)     // конечно объект не найден
     {
      if(!ObjectDelete(0,nameObject))
        {
         if(_LastError>0)
           {
            Print("1 Ошибка №",_LastError);
            ResetLastError();
           }
        }
     }
   ChartRedraw(0);
   if(_LastError>0)
     {                                 // поэтому сразу переходим сюда:
      Print("2 Ошибка №",_LastError);  // Тут ошибка №4202 <Графический объект не найден>
      ResetLastError();
     }
 
mql5:
Try to understand why there is only one message and not every tick, then you won't have any questions.
Sorry, I don't understand. Perhaps you know the answer, and gave me a hint. I also thought about it, I wish you would tell me which function, ObjectFind() or ObjectDelete(), makes an error in _LastError, or any other, maybe I would understand.
sergeev:

judging by the style of the code, it can still be simplified. comment a bit

maybe confused in the if/else?

I have tried many variants (even in this code), not to mention the place of application. And if/else below it seems like you can remove it and the error remains.

By and large, it can be bypassed. You have to write more code checking the object after you deal with it decently. I find it easier to delete it and create it anew with the necessary parameters because its parameters are changing many times during runtime. That's what I encountered and that's why I'm asking.

 
barabashkakvn:

This makes the code easier to read and shows the error immediately:

What's the error? Even if you know the object doesn't exist, can't you check if it exists?

And as for the design, as they say, "taste and colour..."

 
svds75:

What's wrong with it? Even if you know the object doesn't exist, can't you check its existence?

And as for the design, as they say, "taste and colour..."

ObjectFind

Returned value

Ifthe function is successful, it returns the number of the subwindow (0 means main chart window), in which the found object is located. If the object is not found, the function will return a negative number. To get additional information about the error, call the GetLastError() function.

If the object is not found, this is an error. At that, theObjectFind function itselfwill return a negative number and the error number can be obtained.

This is more clear:

//---
   string nameObject="testObject";
   ChartRedraw(0);
   ResetLastError();
   int find=ObjectFind(0,nameObject);
   if(find>=0)     // конечно объект не найден
     {
      if(!ObjectDelete(0,nameObject))

Run it in debug and see the value of variable"find"

Reason: