Mega Code Archive

 
Categories / Delphi / API
 

Temporarily turning off range checking

Question: How do I temporarily turn off range checking for a block of code, then turn it back on if it was originally enabled ? Answer: You can do this in code by using "IFOPT" and "DEFINE". type PSomeArray = ^TSomeArray; TSomeArray = array[0..0] of integer; procedure TForm1.Button1Click(Sender: TObject); var p : PSomeArray; i : integer; begin {$IFOPT R+} {$DEFINE CKRANGE} {$R-} {$ENDIF} GetMem(p, sizeof(integer) * 200); try for i := 1 to 200 do p[i] := i; finally FreeMem(p, sizeof(integer) * 200); end; {$IFDEF CKRANGE} {$UNDEF CKRANGE} {$R+} {$ENDIF} end;