Download MetaTrader 5

heeeeeeeeeeelp: How to save and load the control states of a dialog with IniFileSave() and IniFileLoad()

To add comments, please log in or register
tao zemin.
402
tao zemin.  

The attached is a simplified EA to find the correct way in using IniFileSave() and IniFileLoad() to save and load the control states of a dialog to and from a file. 

After the EA is started. Firstly, I save the origial state of the Edit object by clicking the Save button. then, i made some change to the value of the Edit object. Thirdly, I clicked the Load button.But, Alas! the loaded value in the Edit object is not what I "saved" before. I only simply call  IniFileSave() to save the control states and iniFileLoad() to load the control states(as you can see from the attached file.), have I missed something ? This problem has vexed me for days. PLeeeeease heeeeeeeeelp. waiting for your reply and many thanks for your guidelines.

taozemin.

 


Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
SaveLoadEA.ex5 185 kb
DlgDemo.mqh 7 kb
Jian Chen
Moderator
4585
Jian Chen  

Hi, I just reviewed the UI related source code (for example, Dialog.mqh, WndContainer.mqh, Edit.mqh, etc.).

I thinke that you can not use "IniFileSave()" and "IniFileLoad()" to save/load the content of the edit box. These functions can only save/load the position and status of the dialog box (they are implemented in the Dialog.mqh, but the edit box control doesn't implement the save/load feature.)

So you need to write your own code the load/save the content in your application.

You may refer to the code below: 

void CAppDialog::IniFileSave(void)
  {
   string filename=IniFileName()+IniFileExt();
   int handle=FileOpen(filename,FILE_WRITE|FILE_BIN|FILE_ANSI);
//---
   if(handle!=INVALID_HANDLE)
     {
      Save(handle); 
      FileClose(handle); 
     }
  }

 

bool CDialog::Save(const int file_handle)
  {
//--- check
   if(file_handle==INVALID_HANDLE)
      return(false);
//--- save
   FileWriteStruct(file_handle,m_norm_rect);
   FileWriteInteger(file_handle,m_min_rect.left);
   FileWriteInteger(file_handle,m_min_rect.top);
   FileWriteInteger(file_handle,m_minimized);
//--- result
   return(CWndContainer::Save(file_handle));
  }

 

bool CWndContainer::Save(const int file_handle)
  {
   bool result=true;
//--- loop by elements of group
   int total=m_controls.Total();
   for(int i=0;i<total;i++)
     {
      CWnd *control=Control(i);
      //--- check of pointer
      if(control==NULL)
         continue;
      result&=control.Save(file_handle);
     }
//--- result
   return(result);

 

class CObject
  {
   ..............................

   //--- methods for working with files
   virtual bool      Save(const int file_handle)                         { return(true);   }
  ......................................
  };

 The CEdit class is inherited from CObject (indirectly) but the "Save" method is not overridden to provide more implementations. 

To add comments, please log in or register