GlobalVariableSet and Get unexpected results

 

Here is a short Expert that creates a Dialog with a Button and an Edit box.

The Text in the Button is set to 123 and the edit box is set to 789.

I'm trying to maintain these values using GlobalVariableSet and Get functions.

After loading the Expert and changing timeframes, under the TOOLS  option on the menu bar, the global values show 123 and 789, perfect.

However if I close the Dialog box by clicking on the "X", the global value for the button shows 123 but the edit box value now shows 0.

The button contents are maintained but the edit box contents are lost.

Looks like I need some help.  Thanks.

#property strict

#include <Controls\Dialog.mqh>  
#include <Controls\Button.mqh>
#include <Controls\Edit.mqh>
CAppDialog myInterface;   
CButton button;
CEdit editBox;

double buttonContents, buttonDefault=123;
double editContents,   editDefault  =789;

//+------------------------------------------------------------------
int OnInit()
  {  
    getDialogSettings();
    createInterfacePanel();
    return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------
void OnDeinit(const int reason)
  {  
    saveDialogSettings();
    myInterface.Destroy(reason);      
  }
//+------------------------------------------------------------------
void OnTick()
  {    }
//+------------------------------------------------------------------
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
    myInterface.OnEvent(id,lparam,dparam,sparam);
  } 
//+------------------------------------------------------------------  
void createInterfacePanel()
  {
    myInterface.Create(0,"myInterface",0,50,50,300,180);  
    myInterface.Caption("GlobalVariableTest");
    myInterface.Run(); 
  
    button.Create(0,"button",0,20,10,90,40);
    myInterface.Add(button);
    button.Text(DoubleToString(buttonContents,0));
    button.Color(clrRed);  
  
    editBox.Create(0,"editBox",0,100,10,170,40);
    myInterface.Add(editBox);
    editBox.Text(DoubleToString(editContents,0));
    editBox.Color(clrBlue);
 
    ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,True);
  }   
//+------------------------------------------------------------------
void getDialogSettings()
  {
     buttonContents = GlobalVariableCheck("GV_button") ? GlobalVariableGet("GV_button") : buttonDefault;
     editContents   = GlobalVariableCheck("GV_edit")   ? GlobalVariableGet("GV_edit")   : editDefault;
  }
//+------------------------------------------------------------------
void saveDialogSettings()
  {
    GlobalVariableSet("GV_button", (double)button.Text());
    GlobalVariableSet("GV_edit",   (double)editBox.Text());
  }