-2

Hey guys i have a two questions.
1) How variable act when ( for example think integer maxValue is +- 100 )

sum : integer;
sum+=200;

and sum reaches integer maxValue. Here comes next question related
2) Is there a way in delphi to catch when this situation have place and do somethink else and do it with familiar as try except ? Or if can't is there a way to do it with if then ?

Czcibor
  • 66
  • 6
  • 2
    What language is this code? You really use `+=`? – David Heffernan Oct 31 '16 at 06:09
  • 1
    See also [Cause of Range Check Error (Delphi)](http://stackoverflow.com/q/11658519/576719). A [Range Check Error](http://docwiki.embarcadero.com/RADStudio/en/Compiling#Run.E2.80.91time_Errors_Options) can also be thrown, depending on the the size of the variable types involved in the arithmetic operation. – LU RD Oct 31 '16 at 06:45
  • Yeah, that's not Delphi code... – Jerry Dodge Oct 31 '16 at 13:02

1 Answers1

0

To get the max and min range for the Integer type you can use the following code:

var
  myMin, myMax: Integer;
begin
  myMin := Low(Integer);
  myMax := High(Integer);
end;

EIntOverflow exception is raised:

for integer calculations whose results are too large to fit in the allocated register.

If you tried:

myMax := High(Integer) + 1;

The value would switch to the value of Low(Integer)

P.S. There is no += compound assignment operator in Delphi.

  • Thanks man you help me a lot :). One more question i read on that site with Exception that : >Note: In Delphi Code, EIntOverflow is raised only if overflow checking is turned on. To turn on overflow checking, include the $Q+ directive in project source code, or select Project|Options, choose the Compiler tab, and check the Overflow-checking option in the dialog box. if i compile it to exe and turn on in other computer will it raise exception ? – Czcibor Oct 31 '16 at 02:20
  • For you further read about that directive? It's a *compiler* directive. It applies at compile time, so there is no mechanism to "turn it on in other computer." It's on in the compiler where you create your EXE file. Copying the executable somewhere else will not change the behavior of Overflow checking. – Rob Kennedy Oct 31 '16 at 02:23