Download MetaTrader 5
To add comments, please log in or register
Develop applications to order. Make profit using Freelance service!
MetaQuotes Software Corp.
Moderator
177154
MetaQuotes Software Corp. 2016.02.18 10:33 

New article Graphical Interfaces I: Functions for the Form Buttons and Deleting Interface Elements (Chapter 4) has been published on mql5.com:

This article is the continuation of the first part of the series about graphical interfaces. The first article Graphical Interfaces I: Preparation of the Library Structure (Chapter 1) explains in detail what this library is for. A complete list of links to the articles of the first part is at the end of each chapter. There, you can also download a complete version of the library at the current stage of development. The files must be placed in the same directories as they are located in the archive.

In the previous article, the CWindow class was extended with additions that allowed moving the form over a chart. Now, the form controls react to mouse cursor movements. In this article, we will continue the development of the CWindow class and enrich it with methods that will permit us to manage the form by clicking on its controls. We will enable the program to be closed by a form button as well as implement a minimizing and maximizing feature for the form.

Deletion of Interface Elements

If you followed the sequence of actions suggested in the article and made it to this point, you could see that when the EA is deleted from the chart, all the object of the graphical interface are deleted. We have not discussed methods for deleting graphical objects from the chart yet. Why do the objects get deleted when the EA is deleted? This is provided in the standard library of classes, to be precise, in the destructor of the CChartObject class, the derived classes of which are used in our library. When the program is deleted from the chart, destructors of classes, including this one are called. If an object is attached to this chart, it gets deleted:

//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CChartObject::~CChartObject(void)
  {
   if(m_chart_id!=-1)
      ::ObjectDelete(m_chart_id,m_name);
  }

If the chart symbol or its timeframe is changed when the EA is on the chart, then destructors are not called and graphical objects are not deleted. As the graphical interface is created in the OnInit() initialization function in the main program file, and uninitialization and then initialization are carried out at the change of the symbol or the EA timeframe, the graphical interface is created on top of the existing one. As a result, the first instance of such a change will give you two copies of the objects. If you continue changing the chart symbol or timeframe, you will have many copies of interface objects.

Fig. 4. Test of the form when switching the chart symbol and timeframe.

Fig. 4. Test of the form when switching the chart symbol and timeframe

Author: Anatoli Kazharski

/
To add comments, please log in or register