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

如何关闭文件的一部分范围检查。关闭很简单,但如何在以后恢复到项目设置?下面的伪代码应该解释它:
Unit1;

//here's range checking on or off as per the project setting

code here...

{$R-}

//range checking is off here because the code causes range check errors

code here...

//now I want to revert to the project setting. How do I do that?

code here...

end.
    
已邀请:
请参阅:IFOPT指令。
{$IFOPT R+}
  {$DEFINE RANGEON}
  {$R-}
{$ELSE}
  {$UNDEF RANGEON}
{$ENDIF}
//range checking is off here because the code causes range check errors
//code here...
{$IFDEF RANGEON}
  {$R+}
  {$UNDEF RANGEON}
{$ENDIF}
    
$R
指令包装你的代码:
{$R-} // disable range checking
// do non-range-checked operations here
{$R+} // turn range checking back on
请注意,该指令适用于语句级别。你不能用它包装表达式的一部分。     

要回复问题请先登录注册