Question about deleting objects

 

I want to delete objects whose name contains the specified substring.

When working with my own chart, I use this with no problems:

void objectsDeleteById(string id, int line)
  {
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
      string name;
      if(!objectGetName(i, name) || StringFind(name, id) < 0)
         continue;
      ResetLastError();
      if(!ObjectDelete(name))
         PrintFormat("ObjectDelete error %i. Object \"%s\", line %i.", GetLastError(), name, line);
     }
  }

bool objectGetName(int index, string &var)
  {
   ResetLastError();
   var = ObjectName(index);
   int error = GetLastError();
   if(error == ERR_NO_ERROR && var != NULL)
      return(true);
   Print(StringFormat("ObjectName() error %i. Object index %i.", error, index));
   return(false);
  }

But I need to do the same for objects from another chart.

I can get the number of objects on another chart:

int  ObjectsTotal( 
   long  chart_id,          // chart identifier 
   int   sub_window=-1,     // window index 
   int   type=-1            // object type 
   );

But how can I find out their names?

 

This solves my current problem:

int  ObjectsDeleteAll( 
   long           chart_id,   // chart ID 
   const string     prefix,   // prefix in object name 
   int    sub_window=EMPTY,   // window index 
   int    object_type=EMPTY   // object type 
   );

But still want to know how to get object names of another chart

 
Vladislav Boyko #:

This solves my current problem:

But still want to know how to get object names of another chart

The ObjectName works too , consult this example : 

  long chart=ChartFirst();
  string msg="";
  while(chart>-1){
  int objects_in_chart=ObjectsTotal(chart,0);
  for(int i=0;i<objects_in_chart;i++){
     msg+=IntegerToString(chart)+"::"+ObjectName(chart,i,0)+"\n";
     }
  chart=ChartNext(chart);
  }
  Comment(msg);
 
Lorentzos Roussos #:

The ObjectName works too , consult this example : 

Wow, I didn't know, thanks!

The documentation is silent about this: