GetInteger

可供简便地访问 MQL5 API ObjectGetInteger() 函数来获取绑定实例的图形类的整数属性值。函数有两个调用版本:

无需正确性验证即可获取一个属性值

long  GetInteger(
   ENUM_OBJECT_PROPERTY_INTEGER  prop_id,         // 整数属性标识符
   int                           modifier=-1      // 限定符 
   ) const

参数

prop_id

[输入]  整数图形属性 ID。

modifier=-1

[输入]  限定符 (索引) 整数特征。

返回值

如果成功, 则返回整数类型的属性值, 若出错, 则返回 0。

验证处治的正确性再获取属性值

bool  GetInteger(
   ENUM_OBJECT_PROPERTY_INTEGER  prop_id,      // 整数属性标识符
   int                           modifier,     // 限定符 
   long&                         value         // 链接到变量
   ) const

参数

prop_id

[输入]  对象的整数图形属性值。

modifier

[输入]  限定符 (索引) 整数特征。

value

[输出]  容纳属性整数值的变量引用。

返回值

true - 如果成功, false -如果您未能获取一个整数特征值。

例如:

//--- 例程 CChartObject::GetInteger
#include <ChartObjects\ChartObject.mqh> 
//--- 
void OnStart() 
  { 
   CChartObject object; 
   //--- 通过简便方法获取图表颜色 
   printf("对象颜色是 %s",ColorToString(object.GetInteger(OBJPROP_COLOR),true)); 
   //--- 通过经典方法获取图表颜色 
   long color_value; 
   if(!object.GetInteger(OBJPROP_COLOR,0,color_value)) 
     { 
      printf("获取整数属性出错 %d",GetLastError()); 
      return
     } 
   else 
      printf("对象颜色是 %s",color_value); 
   for(int i=0;i<object.LevelsCount();i++) 
     { 
      //--- 通过简便方法获取水平线宽度 
      printf("水平线 %d 宽度是 %d",i,object.GetInteger(OBJPROP_LEVELWIDTH,i)); 
      //--- 通过经典方法获取水平线宽度 
      long width_value; 
      if(!object.GetInteger(OBJPROP_LEVELWIDTH,i,width_value)) 
        { 
         printf("获取整数属性出错 %d",GetLastError()); 
         return
        } 
      else 
         printf("水平线 %d 宽度是 %d",i,width_value); 
     } 
  }