Why won't these objects be deleted ?

 

I'm calling this function from the EA's deInit, But none of the objects are deleted... Any idea why ?

//---------------- DeleteInfoBackground -------------------------
void DeleteInfoBackground() {
//Objects created has names like: RecW11, RecW12, RecW13, etc..
//But for some reason they won't be deleted...
   string   MajorName;
   int   i = 0;
   while( i < ObjectsTotal() ) {
      MajorName = ObjectName(i);
      if( ObjectName(i) == "RecW"+i ) ObjectDelete(ObjectName(i));
   
      i++;
   
   }
   WindowRedraw();

return (0);
}
//-----------------------------------------------------
 
DayTrader:

I'm calling this function from the EA's deInit, But none of the objects are deleted... Any idea why ?


Found the problem: OrdersTotal() wont work as a loop argument, it has to be assigned to a variable outside the loop. Go figure !

 

If you are deleting objects, you need to start the loop at the top:

for(i = ObjectsTotal()-1; i>= 0; i--){

delete....

}

 

...Not necessarily as I found out...

This code I came up with works just fine. The funny thing is that it generates errors and no objects are deleted if ObjectsTotal() 

is passed as a While-argument. Going via a variable as shown here works just fine as far as I can tell.

//---------------- DeleteInfoBackground -------------------------
void DeleteInfoBackground() {
   int ObjectsAll = ObjectsTotal();
   int   i = 0;
   while(i < ObjectsAll) {
      ObjectDelete("RecI"+i);//Background for the InfoField
      ObjectDelete("RecW"+i);//Background for the WarningField     
      i++;
   }
return (0);
}
//-----------------------------------------------------
Reason: