delete all created objects

 

hello..

i've use this code to delete objects i've created..

it work on mql4 but not in mql5..


could you please help me to fix it

thanks in advance..

//------------------------------------------------------------------//
void deleteObjects()
  {
   int shift=ObjectsTotal(0,-1,-1)-1,strLen=StringLen(qObjName);
   while(shift>=0) {
      string objName=ObjectName(0,shift,-1,-1);
      if(StringSubstr(objName,0,strLen)!=qObjName) {
         shift--;
         continue;
        }
      ObjectDelete(0,objName);
      shift--;
     }
  }
 

Everything works correctly.

It was:

It became:

Code:

//+------------------------------------------------------------------+
//|                                                      Test_en.mq5 |
//|                         Copyright © 2019-2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019-2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property script_show_inputs
//--- input
input string   InpName  = "MyObj";
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   DeleteObjects(InpName);
  }
//+------------------------------------------------------------------+
//| Delete Objects                                                   |
//+------------------------------------------------------------------+
void DeleteObjects(const string name)
  {
   /*
   int  ObjectsTotal(
      long  chart_id,           // chart identifier
      int   sub_window=-1,      // window index
      int   type=-1             // object type
   );
   */
   /*
   string  ObjectName(
      long  chart_id,           // chart identifier
      int   pos,                // number in the list of objects
      int   sub_window=-1,      // window index
      int   type=-1             // object type
   );
   */
   /*
   bool  ObjectDelete(
      long    chart_id,     // chart identifier
      string  name          // object name
   );
   */
   /*
   string  StringSubstr(
      string  string_value,     // string
      int     start_pos,        // position to start with
      int     length=-1         // length of extracted string
   );
   */
   int shift=ObjectsTotal(0,-1,-1)-1,strLen=StringLen(name);
   while(shift>=0)
     {
      string objName=ObjectName(0,shift,-1,-1);
      if(StringSubstr(objName,0,strLen)!=name)
        {
         shift--;
         continue;
        }
      ObjectDelete(0,objName);
      shift--;
     }
  }
//+------------------------------------------------------------------+
Files:
Test_en.mq5  5 kb
 
Vladimir Karputov #:

Everything works correctly.

It was:

It became:

Code:

thanks for reply..

please take a look..

Files:
testing.png  31 kb
testing.mq5  6 kb
 
Vladimir Karputov #:

Everything works correctly.

It was:

It became:

Code:

sorry i forgot to tell you..
i'm using wine to run the platform..

is that make an error..??

 
@Cipud Sableng Could you test your code on Windows? What OS runs wine?
 
Siarhei Siniak #:
@Cipud Sableng Could you test your code on Windows? What OS runs wine?

thanks for reply..


i use debian bookworm..

 
Siarhei Siniak #:
@Cipud Sableng Could you test your code on Windows? What OS runs wine?


tested on windows..
it seem wine bug on my debian..
but i solved this with function

ObjectsDeleteAll(0,qObjName,-1,-1);


and it will delete all objects i've created..

thank you so much you all...

Reason: