Best ways to kill Panel and other objects on the panel completely ? - page 2

 
Alexander Puzanov:

It works :)

It crashes :)

Pulling the plug removes also all objects, as well as throwing the computer out of the window.

 
Doerk:

Pulling the plug removes also all objects

No. Please read the function above - it 1) found prefixes, used by CControlsDialog for its graphic parts in the past (extract it from crashed parts) 2) remove only objects with these 'invalid' prefixes

as well as throwing the computer out of the window.

 :)

 

that why i use

Doerk:

 native MQL4

 
Alexander Puzanov:

No. Please read the function above - it 1) found prefixes, used by CControlsDialog for its graphic parts in the past (extract it from crashed parts) 2) remove only objects with these 'invalid' prefixes

 :)

The question is the same: How do you create the instances, and how and where do you delete or destroy them. I studied the deepest kernels of these classes. They do not crash and they´re clean in view of memory management - if you use them right. A simple way to "crash" an instance is, when you do not use the message queue and i. E. you have a button to delete the whole "window" which´s functionality is executed inside the instance. What you describe sounds exactly like that, and that´s a safe way to confuse MQL and to crash at least the debugger. But believe me, nothing of these things happen when you´re code is clean in view of OOP.

Post your code.  

 
Doerk:

The question is the same: How do you create the instances, and how and where do you delete or destroy them

Panel constractor called only once - at OnInit, destructor - only once, at OnDeinit, it crashes at OnDeinit. It was OK a few months ago, but started after one of these months updates. But this isn't a problem for me - my codes updated, every next OnInit clean unnecessary panel parts

Post your code.  

It contains 3098 lines. I hope you can investigate Young Ho Seo code

 
Alexander Puzanov:

Panel constractor called only once - at OnInit, destructor - only once, at OnDeinit, it crashes at OnDeinit. It was OK a few months ago, but started after one of these months updates. But this isn't a problem for me - my codes updated, every next OnInit clean unnecessary panel parts

It contains 3098 lines. I hope you can investigate Young Ho Seo code

What do you mean by "constructor" ? The constructor is executed BEFORE OnInit(), and the destructor AFTER OnDeinit(). If you mean the .Create() function, you cannot put the .Create() function inside the OnInit() just like that, you need to check if the OnInit() was already executed, because the OnInit() is called after each change of the timeframe and after each change of the settings. Use a static variable or function to check if the OnInit() was executed. And you also do not need to use the .Destroy() in OnDeinit(), because, assuming that your panel object is a static object, this will be deleted by MQL when the EA is removed, and this will result in deletion of ALL objects which belong to the CArrayObj object which is part of every CWndContainer and every class deriving from it. 

Maybe this is already your key:

bool _IsInit(void)
   {
   static bool init=false;
   bool result=init;
   init=true;
   return result;
   }

int OnInit()
   {
   if (_IsInit())
      return INIT_SUCEEDED;

   //--- create what you ever want to create here
   }
 
Marco vd Heijden:

that why i use

And that´s really a pity. You seem to have good ideas in view of correlation, programming and so on, but MQL4 gives you very tight barriers.

I can only recommend to everybody who is at least able to understand OOP, to reset his brain to basics and to re-learn programming on an OOP basis. OOP, here MQL5, definitely brings you on the next level of programming where you have possibilities that you never can achieve with native programming, at a efficiency which is also so many times higher than with native programming. One who claims it isn´t like that, simply never understood OOP entirely and the power behind it, especially inheritance and virtual overloading, which are THE ultimate keys at all. Just using the standard library is not real OOP programming, but it can be a good start to get into it. MQL5 is simply amazing and it´s 100% compatible with MT4 too.

 
Doerk:

If you mean the .Create() function, you cannot put the .Create() function inside the OnInit() just like that, you need to check if the OnInit() was already executed

1. Thanks, will check it, if this problem occurs somewhere again

2. Please look into any MetaQuotes codes in the standard MT4 or MT5 distributive - SimplePanel.mq4 or SimplePanel.mq5 or ChartPanel.mq5. Seems like you know how to use the 'standard library' much better then SL authors - all .Create() functions in MqtaQuote's codes placed into OnInit without any 'run only once' conditions

And you also do not need to use the .Destroy() in OnDeinit()


And all .Destroy() placed into OnDeinit in the MetaQuotes codes. Maybe this is because every new OnInit (.Create) always follows after OnDeinit (.Destroy) so there is no crime in creating a new set after deleting the old one?

 
Alexander Puzanov:

1. Thanks, will check it, if this problem occurs somewhere again

2. Please look into any MetaQuotes codes in the standard MT4 or MT5 distributive - SimplePanel.mq4 or SimplePanel.mq5 or ChartPanel.mq5. Seems like you know how to use the 'standard library' much better then SL authors - all .Create() functions in MqtaQuote's codes placed into OnInit without any 'run only once' conditions


And all .Destroy() placed into OnDeinit in the MetaQuotes codes. Maybe this is because every new OnInit (.Create) always follows after OnDeinit (.Destroy) so there is no crime in creating a new set after deleting the old one?

With the Simplepanel it makes sense, because indicators initialize different from EAs. Does the other sample have the same problems as your code? I don´t know this thing. You cannot compare these samples to your code anyway, because the do nothing and can nothing. But I guess your code is there to produce something constructive and therefore you will have other objects and vars, that you surely don´t want to reset and recalculate after only the timeframe has changed.  
 
I has deal with this problem in the indicator and EA, in MT4 and MT5. Loading & saving data in forms organized in different ways in different cases. But it is not related to panel destructor issues
Reason: