You can use ObjectsDeleteAll()
ObjectsDeleteAll(0,0,-1);
a better way can be to first check if the object exists before creating it.
then when the ea gets re-initialized, it will see that the object already exists, and skip creation so there will never be any duplicates.
I was looking for such a way too. But is this straightforward ?
Please enlighten me if you can. :)
Return Value
If successful the function returns the number of the subwindow (0 means the main window of the chart), in which the object is found.
If the object is not found, the function returns a negative number.
I will try this. I will let you know if it can be successful.
Thanks for your help.
Kind regards.
What exactly is the problem here? I don´t get it. You cannot really destroy an object which was create with the library by using ObjectDelete. Either you use the classes or you use native MQL4. Maybe it disappears with ObjectDelete, but clean programming is something different. Please post the code and I can tell you what´s going wrong. The screenshot does not show me a CPanel instance, it shows a CDialog.
" I get sucess when I call "int OnInit()" function" for first time but when I repeat it couple of times then My panel become really ugrl looking with several other panels stacked on top of each other.".
One thing upfront: .Destroy() does not destroy the object panel, it destroys the content contained in the object panel. If the definition is like this:
CDialog panel;
panel.Create(....)
then the
panel.Destroy()
should destroy the screen objects which have been created by the CDialog class. If you try this:
CDialog * panel = new CDialog;
panel.Create(...)
etc., and then later
delete panel;
everything should be gone, cause this will result in a call of the destruction in CWndContainer, which will result in a call of the .Delete() in CArrayObj and this will result in deletion of the contained instances which will result in destroying of all contained objects cause the free mode is used by default by CWndContainer. Got it? ;) But define the instance of the class outside OnInit(), cause otherwise, it will become a local instance and this will be deleted and destroyed when OnInit() ends. Same with normal definition of the panel, it must be defined as a static object variable outside the function.
Doerk
There is a lot of details in this solution - too hard to describe with my English. But i can show the most important part - search'n'kill function itself
void CControlsDialog::Clean_Objects(string s_Valid_Prefix) { int i_Object_ID = 0; string s_Name, s_Invlid_Prefix = "-----" ; while(StringLen(s_Invlid_Prefix) > 0) { ObjectsDeleteAll(0, s_Invlid_Prefix); s_Invlid_Prefix = ""; i_Object_ID = ObjectsTotal(); while(i_Object_ID-- > 0) { s_Name = ObjectName(0, i_Object_ID); if(StringFind(s_Name, "MinMax") != 5) continue; s_Invlid_Prefix = StringSubstr(s_Name, 0, 5); if(s_Valid_Prefix == s_Invlid_Prefix) s_Invlid_Prefix = "-----"; else break; } } }
There is a lot of details in this solution - too hard to describe with my English. But i can show the most important part - search'n'kill function itself
Totally wrong way. The classes may be buggy, but crash? No. And if there is something with this classes which is really working good, then it is object and memory management. But due to lack of documentation, most people seem to misunderstand how to it all.
@Young - please post the snipped ...
Totally wrong way.
It works :)
The classes may be buggy, but crash? No

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Traders and Coders
I am currently playing around with Panel for sometime.
I found that Panel object is little bit clumsy at the moment.
I created panel with several buttons and labels on the panel.
When the "int OnInit()" function takes place (for example, when new input variable set by users), I want to remove the panels and the objects on the panel completely from the chart to create brand new panel.
I am currently using this code line below. I get sucess when I call "int OnInit()" function" for first time but when I repeat it couple of times then My panel become really ugrl looking with several other panels stacked on top of each other.
See the screenshot below for better understanding.
I tried following code as well but it did not work at all.
So How to remove the existing panel completely and create a brand new panel ?
Your ideas will be really appreciated.
Kind regards.