Главная страница | назад





Article #17410: Temporarily turning off range checking.

 Question and Answer Database

FAQ2410D.txt   Temporarily turning off range checking.
Category   :Windows API
Platform    :All
Product    :All 32 bit  

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;

7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99