【问题标题】:What is the maximum string size or string length for ObjectSetText in MQL4?MQL4 中 ObjectSetText 的最大字符串大小或字符串长度是多少?
【发布时间】:2021-04-17 16:11:35
【问题描述】:
Comment(MSGARRAY[0], "\n" , 
MSGARRAY[01], "\n" , 
MSGARRAY[02] , "\n" , 
" error:" , err, "\n" ,   
"") ; 

不截断字符串(见下图左上角的黄色文字)但是

  ObjectCreate(tLabel,23,0,Time[0],PRICE_CLOSE);
  ObjectSet(tLabel, OBJPROP_CORNER, myCorner );
  ObjectSet(tLabel,OBJPROP_XDISTANCE,xPos);
  ObjectSet(tLabel,OBJPROP_YDISTANCE,yPos);
  ObjectSetText(tLabel,name,myFontSize,myFont,Color); 

截断。

我做错了什么/做错了什么?

谢谢

编辑: 我正在从文件中读取文本,这就是发生截断的地方。

int h = FileOpen(FileName, FILE_TXT|FILE_READ); 

if(h != INVALID_HANDLE) 
{ 

Comment("File "+FileName+" not found in MQL FILES FOLDER."); 

for (int c=0; !FileIsEnding(h) && c<9999; c++) 
{ 
     if (FileIsEnding(h)) break; 

     MSGARRAY[c]=FileReadString(h); 
} 

     FileClose(h); 
} 
else 
{ 
     Comment(FileName +" not found in MQL FILES FOLDER. OR... File Must Be Open..."); 

} 

【问题讨论】:

    标签: string object mql4 truncation


    【解决方案1】:

    文本作为对象的最大文本长度为 63 个字符。您可以使用以下代码看到这一点:

       string id="test";
       ObjectCreate    (0, id, OBJ_LABEL, 0, 0, 0);
       ObjectSet       (id, OBJPROP_CORNER, 0);
       ObjectSet       (id, OBJPROP_XDISTANCE, 10);
       ObjectSet       (id, OBJPROP_YDISTANCE, 10);
       ObjectSetText   (id, "12345678901234567890123456789012345678901234567890123456789012345", 10, "Arial", clrBlack);
    

    解决方法是使用两个对象,你可以使用TextGetSize() 找到第二个对象的偏移量。

    【讨论】:

    • 感谢您的回复。我正在从 TXT 文件中读取,而不是从对象中读取。 MQL4 文档中哪里定义了最大字符串长度?
    • 从哪里阅读并不重要。对象名称和文本都限制为 63 个字符。虽然文档中没有具体定义,但上面的示例显示了这种情况。检查this page of the documentation,它指的是对象名称限制。
    猜你喜欢
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2010-09-13
    • 2016-09-11
    • 2022-01-19
    • 2010-10-23
    相关资源
    最近更新 更多