Issue with AppDialog Library: Unexpected Change in Panel Name

 

Hello there

I'm encountering an issue with the AppDialog standard library in MQL5 and would appreciate some assistance in resolving it. The problem I'm facing is related to the unexpected change in the panel name during program initialization, specifically within the CWndContainer module.

Here's a brief overview of the problem:

  1. I provide a string value as the program name in the CAppDialog::Create function. This name is intended to be assigned to the m_name parameter of the CDialog class.

  2. However, when the program progresses and the CWndContainer::Create function is called, I noticed that the m_name parameter changes from the original string value to an integer. This alteration can be seen in the attached screenshots.


To outline the flow of the program:

1. The initial value of `m_name` is set within the `CAppDialog::Create` and the within CAppDialog::CreateCommon function.

2. The `CAppDialog::Create` function then calls `CAppDialog::CreateExpert`.

3. Within `CAppDialog::CreateExpert`, the `CDialog::Create` function is invoked.

4. Finally, `CDialog::Create` triggers the `CWndContainer::Create` function, where the unexpected change occurs, replacing the original string value of `m_name` with an integer.

My code:

#include <Controls\Dialog.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CTradingPanel : public CAppDialog
  {

public:
                     CTradingPanel(void);
                    ~CTradingPanel(void) {};

   virtual bool      Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2);
   virtual void      Destroy(const int reason);

  };

//+------------------------------------------------------------------+
//| Class initialization function                                    |
//+------------------------------------------------------------------+
CTradingPanel::CTradingPanel(void)
  {
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CTradingPanel::Create(const long chart, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2)
  {

   if(IsStopped())
      return false;
   ResetLastError();
   if(!CAppDialog::Create(chart, name, subwin, x1, y1, x2, y2))
     {
      Print("Function: " + __FUNCTION__ + " line: " + (string)__LINE__ + " Error " + string(GetLastError()));
      return false;
     }
   return true;
  }
//+------------------------------------------------------------------+
//| Application deinitialization function                            |
//+------------------------------------------------------------------+
void CTradingPanel::Destroy(const int reason)
  {
   CAppDialog::Destroy(reason);
  }
CTradingPanel *TradingPanel;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   TradingPanel = new CTradingPanel;
   string panelName = "TradingPanel";
   
   if(!TradingPanel.Create(ChartID(), panelName, 0, 0, 17, 200, 420))
      return(INIT_FAILED);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   TradingPanel.Destroy(reason);
   delete TradingPanel;
  }


//+------------------------------------------------------------------+

I kindly request your assistance in identifying the cause of this issue and finding a suitable solution.
Thank you very much

Documentation on MQL5: Standard Library
Documentation on MQL5: Standard Library
  • www.mql5.com
Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Screenshot_.png  28 kb
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
 

Hello @Alain Verleyen

Can you help me with this issue?

Is this my mistake or library problem?

Thank you

 
Reza Khanlou:

4. Finally, `CDialog::Create` triggers the `CWndContainer::Create` function, where the unexpected change occurs, replacing the original string value of `m_name` with an integer.

The app dialog is assigned a new 5-digits random number on each initialization of the program (e.g., timeframe change or terminal restart).

This random number is used as a prefix for all objects' names created on that dialog (as in your screenshot above).

More importantly, that 5-digits random number (dialog identifier) is always saved as fixed-width field inside the .dat file that is created inside \MQL5\Files\ folder upon destroying the dialog.

The standard library automatically saves the dialog's previous state (coordinates and minimized state) upon Destroy().

\MQL5\Include\Controls\Dialog.mqh

void CAppDialog::Destroy(const int reason)
  {
   IniFileSave();
  }

However, to be able to restore the dialog position/minimized state (e.g, upon timeframe change or terminal restart),

you should call CAppDialog::IniFileLoad() inside your expert's OnInit() function:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   TradingPanel = new CTradingPanel;
   string panelName = "TradingPanel";

   if(!TradingPanel.Create(ChartID(), panelName, 0, 0, 17, 200, 420))
      return(INIT_FAILED);

   Print("TradingPanel.Name()=", TradingPanel.Name());

//--- read the previous state of the program "dialog position and minimized state"
   TradingPanel.IniFileLoad();

//--- run application
   TradingPanel.Run();

   return(INIT_SUCCEEDED);
  }
 
amrali #:

The app dialog is assigned a new 5-digits random number on each initialization of the program (e.g., timeframe change or terminal restart).

This random number is used as a prefix for all objects' names created on that dialog (as in your screenshot above).

More importantly, that 5-digits random number (dialog identifier) is always saved as fixed-width field inside the .dat file that is created inside \MQL5\Files\ folder upon destroying the dialog.

The standard library automatically saves the dialog's previous state (coordinates and minimized state) upon Destroy().

\MQL5\Include\Controls\Dialog.mqh

However, to be able to restore the dialog position/minimized state (e.g, upon timeframe change or terminal restart),

you should call CAppDialog::IniFileLoad() inside your expert's OnInit() function:

Thank you very much
Reason: