Description |
The $OverFlowChecks compiler directive determines whether Delphi should add code to check for integer and enum operation value overflows.
This is set Off by default, meaning that a bad integer or enum operation will pass unnoticed, revealing itself in a difficult to debug part of the code.
It is recommended to switch on $OverFlowChecks in order to detect overflows before they cause problems. This will result in the raising of an exception, allowing code testing to correctlt identify the point of failure.
|
| Notes | $OverFlowChecks is equivalent to $Q.
It can and should only be set once in your code.
The default value is $OverFlowChecks Off.
| | Related commands | $Q | | Determines whether Delphi checks integer and enum bounds |
|
Download this web site as a Windows program.
|
|
|
|
Example code : Trapping overflow values | var
myNumber : Byte;
begin
 // Set overflow checking on
{$OverFlowChecks On}
 // A byte can hold numbers up to 255
myNumber := 255;
ShowMessage('myNumber = '+IntToStr(myNumber));
 // But incrementing beyond 255 will throw an exception
Inc(myNumber);
ShowMessage('myNumber = '+IntToStr(myNumber));
end;
| Show full unit code | myNumber = 255
Delphi throws the EIntOverflow exception | Example code : Ignoring overflow values | var
myNumber : Byte;
begin
 // Set overflow checking off
{$OverFlowChecks Off}
 // A byte can hold numbers up to 255
myNumber := 255;
ShowMessage('myNumber = '+IntToStr(myNumber));
 // But incrementing beyond 255 will wrap around to 0
Inc(myNumber);
ShowMessage('myNumber = '+IntToStr(myNumber));
end;
| Show full unit code | myNumber = 255
nyNumber = 0 |
|
|
Delphi Programming © Neil Moffatt . All rights reserved. | Home Page
|
|