Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch off Delphi range checking for a small portion of code only

How can one switch off range checking for a part of a file. Switching off is easy, but how do I revert to the project setting later on? The pseudo-code below should explain it:

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.
like image 706
Giel Avatar asked Feb 14 '11 22:02

Giel


2 Answers

See: IFOPT directive.

{$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}
like image 137
Sertac Akyuz Avatar answered Oct 27 '22 01:10

Sertac Akyuz


Wrap your code in $R directives:

{$R-} // disable range checking
// do non-range-checked operations here
{$R+} // turn range checking back on

Note that the directive applies at the statement level. You cannot wrap just part of an expression with that.

like image 39
Rob Kennedy Avatar answered Oct 27 '22 01:10

Rob Kennedy