关闭Delphi范围检查一小部分代码

前端之家收集整理的这篇文章主要介绍了关闭Delphi范围检查一小部分代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何关闭范围检查文件的一部分.关闭是很容易的,但是如何稍后恢复到项目设置?下面的伪代码应该解释一下:
  1. Unit1;
  2.  
  3. //here's range checking on or off as per the project setting
  4.  
  5. code here...
  6.  
  7. {$R-}
  8.  
  9. //range checking is off here because the code causes range check errors
  10.  
  11. code here...
  12.  
  13. //now I want to revert to the project setting. How do I do that?
  14.  
  15. code here...
  16.  
  17. end.

解决方法

见: IFOPT directive.
  1. {$IFOPT R+}
  2. {$DEFINE RANGEON}
  3. {$R-}
  4. {$ELSE}
  5. {$UNDEF RANGEON}
  6. {$ENDIF}
  7. //range checking is off here because the code causes range check errors
  8. //code here...
  9. {$IFDEF RANGEON}
  10. {$R+}
  11. {$UNDEF RANGEON}
  12. {$ENDIF}

猜你在找的Delphi相关文章