text: delphi - Why doesn't "i := i + 1" give a range-check error for Integers and larger types? - Stack Overflow
  Why doesn't "i := i + 1" give a range-check error for Integers and larger types?
  If I declare i as Byte, Word, Shortint or TinyInt I get a range-check error, as expected.
  If I declare i as LongWord, Cardinal, Integer, LongInt or Int64 it just goes through the while loop and gets to show the negative or 0 value, which i gets when you pass the upper bound.
  Does Delphi 7 not support range checking for 32-bit and 64-bit numbers?
  delphi range-checking share|improve this question edited Apr 18 '12 at 13:13
  The operation i + 1 doesn't actually produce a range check error. The assignment operation does.
  Delphi evaluates the constant '1' as an Integer and so the right hand side will produce a result that is either an Int64 or an Integer (The larger of i's type and Integer).
  If we expand the line out we get the following
  i := temp
  temp will either be 32 or 64 bits, and will overflow if it hits the upper bound. By the time we do the assignment, we have a perfectly valid 32 or 64bit value so there's no possibility of a range check failure if i is 32bits or more.
  If i is less than 32 bits, it will raise a range check if temp is too large to fit.
  For i >= 32bits, you can catch the overflow error like so:
  share|improve this answer edited Apr 18 '12 at 11:13
  Thanks for your explanation which helped with some direction. I did some more testing, instead adding i+1 I added i+j with both i and j of the same type. This resulted in the same problem. So I'd say the "+" operator makes the result an integer. Strangely though: if I use Inc(i), then no matter what type I use, I don't get a rangecheck error. I found the {$Q+} to give me an integer overflow exception.
  Sorry, yes, that should have been a Q, not an O :)
  So in the end I was using the wrong tool for the job and should have been looking for an overflow instead of a rangecheck.
  Not the answer you're looking for?	Browse other questions tagged delphi range-checking or ask your own question.	asked
  12How are the basic Delphi types related to each other?11Switch off Delphi range checking for a small portion of code only6I cannot use SHL (shift left) with int64 variables3Why no runtime error when clearly writing over array bounds?4How to "build" a negative 32 bit integer from bytes without a range check error?3Check if number is of Integer type0Range check error while evaluating constants1Range checking using regular expressions?71Is it more efficient to perform a range check by casting to uint instead of checking for negative values?0conditional statement to verify range provided by #define(d) integers in header for transaction module (.cpp)