DeleteObjectsByPrefix() - Please tell me what I am doing wrong.

 

Whenever my indicators create objects I prefix their names with the short name of the indicator so that upon deinitialisation they remove only 'their' objects. To remove them I want to use the function below. For some reason though it doesn't seem to be working right. Could someone please point out where I am going wrong.


//--------------------------------------------------------------------
//Function: DeleteObjectsByPrefix
//Purpose:  Deletes objects with prefix of passed string
//Inputs:   Prefix (string)
//Returns:  (void)
//--------------------------------------------------------------------
void DeleteObjectsByPrefix(string Prefix){
   int L = StringLen(Prefix);
   int i = 0; 
   int ObjectsTotal_ = ObjectsTotal();
   string ObjName;
   for(i=ObjectsTotal_-1;i<=0;i--) {
       ObjName = ObjectName(i);
       if(StringSubstr(ObjName, 0, L) != Prefix) {     
          continue;    
       }
       ObjectDelete(ObjName);
   }//end for(i=ObjectsTotal_;i<=0;i--) {
   WindowRedraw();
}//end void DeleteObjectsByPrefix(string Prefix){
 

.

void ObjectsDeletePrefixed(string sPrefix) {
  for(int i=ObjectsTotal()-1; i>=0; i--) {
    if(StringFind(ObjectName(i),sPrefix)==0) ObjectDelete(ObjectName(i));
  }
}
 
sxTed:

.

Thanks for your help sxTed.