Errors, bugs, questions - page 1542

 
comp:

Why does this class compile under MT4 but not under MT5?

If you remove operator definition in this class, it starts compiling under MT5. This seems to be a bug in the MT5 compiler.
 
comp:
If you remove operator definition in this class, it starts compiling under MT5. This seems to be a bug in compiler of 5.

Try substituting

__MQL5__

to

__MQL5BUILD__.

 
coderex:

Try substituting

__MQL5__

to

__MQL5BUILD__

To not be confused by conditional compilation, I removed it.

class CHARTOBJECT
{
public:
  template <typename T>
// для MT4 надо заменить ENUM_OBJECT_PROPERTY_STRING на int  
  void SetProperty( const ENUM_OBJECT_PROPERTY_STRING id, const T Value, const int Modifier = 0 ) const
  {
    const string sType = typename(T);

    if (sType == "double")
      ::ObjectSetDouble(0, "", id, Modifier, (double)Value);
    else if (sType == "string")
      ::ObjectSetString(0, "", id, Modifier, (string)Value);
    else
      ::ObjectSetInteger(0, "", id, Modifier, (long)Value);

    return;
  }
  
  virtual void operator =( const string Value ) const
  {
    this.SetProperty(OBJPROP_TEXT, Value);

    return;
  }
};

Five can't compile, four is OK.

 
comp:

To avoid confusion with conditional compilation, I removed it

Five can't compile, four is OK.

What is the error log?
 
coderex:
What's the error log?
'ObjectSetDouble' - no one of the overloads can be applied to the function call
'ObjectSetInteger' - no one of the overloads can be applied to the function call

 
comp:
'ObjectSetDouble' - no one of the overloads can be applied to the function call
'ObjectSetInteger' - no one of the overloads can be applied to the function call

I think I've got it. In MT5 you must clearly specify all three ENUM_OBJECT_PROPERTY_STRING, ENUM_OBJECT_PROPERTY_INTEGER and ENUM_OBJECT_PROPERTY_DOUBLE. In MT4, simply specify int, and everything will work.

In this case I do not even know if MQL5 is a better solution than MQL4.

 
comp:
'ObjectSetDouble' - no one of the overloads can be applied to the function call
'ObjectSetInteger' - no one of the overloads can be applied to the function call

You passed an invalid parameterENUM_OBJECT_PROPERTY_STRING id as an input parameter to method ObjectSetDouble and ObjectSetInteger.

In general, do not make a common library for two languages, there would be more confusion.

 
comp:

I think I've figured it out. In MT5 all three ENUM_OBJECT_PROPERTY_STRING, ENUM_OBJECT_PROPERTY_INTEGER and ENUM_OBJECT_PROPERTY_DOUBLE must be clearly specified. In MT4, simply specify int, and everything will work.

Exactly!

#ifdef __MQL4__
  #define ENUM_OBJECT_PROPERTY_DOUBLE int
  #define ENUM_OBJECT_PROPERTY_STRING int
  #define ENUM_OBJECT_PROPERTY_INTEGER int
#endif

class CHARTOBJECT
{
public:
  template <typename T>
  void SetProperty( const int id, const T Value, const int Modifier = 0 ) const
  {
    const string sType = typename(T);

    if (sType == "double")
      ::ObjectSetDouble(0, "", (ENUM_OBJECT_PROPERTY_DOUBLE)id, Modifier, (double)Value);
    else if (sType == "string")
      ::ObjectSetString(0, "", (ENUM_OBJECT_PROPERTY_STRING)id, Modifier, (string)Value);
    else
      ::ObjectSetInteger(0, "", (ENUM_OBJECT_PROPERTY_INTEGER)id, Modifier, (long)Value);

    return;
  }
  
  virtual void operator =( const string Value ) const
  {
    this.SetProperty(OBJPROP_TEXT, Value);

    return;
  }
};

Now it compiles on both platforms. There is clearly an error in Help 5.

 
comp:

Exactly!

It now compiles on both platforms. There's clearly an error in the five's help.

What mistake?
 
Slawa:
What is the error?

For example, in the ObjectSetInteger description now

bool  ObjectSetInteger( 
   long    chart_id,          // идентификатор графика 
   string  name,              // имя 
   int     prop_id,           // свойство 
   long    prop_value         // значение 
   );

It should be.

bool  ObjectSetInteger( 
   long                          chart_id,  // идентификатор графика 
   string                        name,      // имя 
   ENUM_OBJECT_PROPERTY_INTEGER  prop_id,   // свойство 
   long                          prop_value // значение 
   );

What about in five with IndicatorBuffers when the number of CURRENT buffers cannot be set rigidly via #property? In fours there is no restriction with this.

Reason: