Your _Integer2 > MaxInt
will never return True
because it is impossible. The value of an Integer
cannot ever be greater than the greatest possible value of an Integer
.
However, you can enable overflow checking:
var
x, y, z: Integer;
begin
{$Q+} // enable overflow checking
x := MaxInt div 2;
y := MaxInt div 4;
z := x + y; // fine
ShowMessage(z.ToString);
x := MaxInt div 2;
y := 3 * (MaxInt div 4);
try
z := x + y; // exception
ShowMessage(z.ToString); // won't run
except
on EIntOverflow do
ShowMessage('Integer overflow.');
end;
Here I enable overflow checking locally using a compiler directive: {$Q+}
. If you want to use overflow checking in a particular function or procedure, you can use this together with a resetter, like in this answer but opposite.
You can also turn it on for an entire project using Project > Options > Delphi Compiler > Compiling > Runtime errors > Overflow checking. Just remember that this setting is per configuration (for instance, debug vs. release).