GUI

 

Hello everyone,

I'm not making any progress with this code atm. If I attempt to modify the code "Forum_Test" = "Indenifier not declared ".

My question. CForum_Test can see variables, but Forum_Test.Run() will fail. I'm still trying to understand classes.

//+------------------------------------------------------------------+
//|                                                   Forum_Test.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CForum_Test : public CAppDialog
  {
private:
   double            ASK,BID;
   double            Balance;
   double            Equity;
   string            Currency;

 public:

   double            StopLevel;
   double            StopLoss;
   double            TakeProfit;
   double            Risk;
   int               Orders;

                     CForum_Test(void){};
                    ~CForum_Test(void){};
  };

CForum_Test Forum_Test;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   if(!Forum_Test.Create(ChartID(),"Forum_Test",0,20,20,320,420))
     {
      return (INIT_FAILED);
     }
   Forum_Test.Run();

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
 
GrumpyDuckMan: CForum_Test can see variables, but Forum_Test.Run() will fail.

You don't have a CForum_Test::Run(), so you are calling the parent class (CAppDialog,) method and (of course,) that can't see your variables.

If you make a CForum_Test::Run(), you can do whatever with your variables and then call the parent method.

 

Hello again,

Thank you, whroeder1

Can you help me with this error message please.

 'OnClickCslBTN' - member function already defined with different parameters

//+------------------------------------------------------------------+
//|                                                   Forum_Test.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CForum_Test : public CAppDialog
  {
private:
   double            ASK,BID,Balance,Equity;
   string            Currency;

public:
   double            StopLevel,StopLoss,TakeProfit,Risk;
   int               Orders;

                     CForum_Test(void){};
                    ~CForum_Test(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 bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
  };

CForum_Test Forum_Test;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class Cstoploss:public CAppDialog
  {
public:
   double            sl,tp,price;
   CButton           CslBTN;

   bool              OnClickCslBTN(void);

                     Cstoploss(void){};
                    ~Cstoploss(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 bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
  };

Cstoploss StopLevel;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(Cstoploss)

ON_EVENT(ON_CLICK,CslBTN,OnClickCslBTN)
EVENT_MAP_END(CAppDialog)

// 'OnClickCslBTN' - member function already defined with different parameters
bool Cstoploss::OnClickCslBTN(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {
   if(!Cstoploss::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);
   if(!OnClickCslBTN())
      return(false);
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int OnInit()
  {
   if(!StopLevel.Create(ChartID(),"Forum_Test",0,20,20,320,420))
     {
      return (INIT_FAILED);
     }
   StopLevel.Run();

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {

  }

//+------------------------------------------------------------------+
 
  1. GrumpyDuckMan 'OnClickCslBTN' - member function already defined with different parameters

  1. Self explanatory.
    Your code
     Your class
    bool Cstoploss::OnClickCslBTN(
       const long chart,
       const string name,
       const int subwin,
       const int x1,
       const int y1,
       const int x2,
       const int y2
    ){
    
    bool OnClickCslBTN(
        void
    
    
    
    
    
    
    );
    

  2. You don't really mean to call your method recursively do you?
    bool Cstoploss::OnClickCslBTN(const long chart,...){
       if(!Cstoploss::Create(chart,name,subwin,x1,y1,x2,y2))
          return(false);
       if(!OnClickCslBTN()) ...


 
whroeder1:
  1. Self explanatory.
    Your code
     Your class

  2. You don't really mean to call your method recursively do you?


Hello Whroeder1,

Can you please elaborate a little more for me. A couple of months ago I tried to use classes and functions like what I'm trying to do now. I gave up because I don't really understand the error messages.

 
GrumpyDuckMan: Can you please elaborate a little more for me.
  1. Elaborate on what? It is self explanatory. You declared in your class that the method takes no arguments, and then made the method with multiple arguments. What part of "already defined with different parameters" is unclear?
  2. Elaborate on what? What part of your function calls itself is unclear?
 
whroeder1:
  1. Elaborate on what? It is self explanatory. You declared in your class that the method takes no arguments, and then made the method with multiple arguments. What part of "already defined with different parameters" is unclear?
  2. Elaborate on what? What part of your function calls itself is unclear?

Thank you, whroeder1

I didn't realize what I had done. 

Reason: