[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Integer overflow problems

Posted on 2006-06-22
Medium Priority
Last Modified: 2012-05-05

I have a project with many calculations inside some timers.
After some seconds (~ 90000, almost a day) it pop up a message sayint "integer overflow"
and i have to terminate the program.

I've turned on Overflow checks in Options ---> Compiler.
I've put this line at the beggining : {$OVERFLOWCHECKS ON}

In EVERY calculation i've put :

Except on Exception do
  ErLog.Add('Error in "Section 1"');

(variables ErLog:TStringList; ErPath:String;)

BUT the program does NOT create an error log. It gives the error messages again and again.
It bypass the try ...except as it seems....

I tried to run the program from delphi with timer interval 1msec and let it run for 2million times !
No error. I can reproduce the error and i dont know how to find it.

Can you help ?
Thanks in advance.
Question by:CodedK
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
LVL 28

Assisted Solution

2266180 earned 300 total points
ID: 16966744
I would blame it on the "sizes"/ if you have D7+, then compile your project and check your hint messages. everywhere where you see that the sizes missmatch and that it was made larger: make sure you change the type so that the warning goes away. (sorry, but I cannot rember the hint message and can't seem to be able to reproduce it right away)

I also found an interesting article:
LVL 10

Accepted Solution

atul_parmar earned 300 total points
ID: 16966777
The error means that you are assining a large value (what can not be stored in integer) to integer variable.

just change the data type from integer to longint; or int64
LVL 16

Author Comment

ID: 16968399
Thanks ciuly :) . There are no hints !!!
(only a depricated command at some point BUT i've used it since the version 1
of this project without any problems).
Before i post this question i was reading that article :)
I've placed everywhere "*1.0" in multiplications. I did everything the article says.

Atul_parmar thank you, of course i know that, i could replace int with int64 but this would make the app,
use TOO much memory.
And i dont assign big values (2 or MAX 3 digits) and in every tick of the timer they turn to zero.

I'm trying to reproduce the problem by running the program from Delphi 7,
I've tried with interval '1 sec' (as it is) and let it run for 2 days.
I've tried with interval '1 msec' and let it run for 15 hours (15.000 hours of calculations in real life)
BUt there was no problem.

When i run the program from windows then at some point ~80.000 - 90.000 seconds (1 day)
there is that integer flow message popping up every second.

The problem is WHY it bypass the TRY... EXCEPT ?

Thanks for your help.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 16

Author Comment

ID: 16968411
Ciuly can you explain more about the sizes.. What do you mean by size mismatch?
LVL 28

Expert Comment

ID: 16968468
well .. when you have operands of some type and result is anotehr type.


byte*byte = word
but if you do byte = byte*byte you have a type size issue as byte*byte will not fit in a byte.

until we figure it out, install madhis madexcept. compile with debug info and all that, and that catch the exception like that (maybe it's not an exception but an error, in which case a simple catch exception deosn't help)

let the app run until it booms.

I'll try to think of other reasons that could cause an integer overflow in the OS as this is probably not delphi issue.
LVL 10

Expert Comment

ID: 16968491
you can also try with unsigned if you don't require -ve numbers

Assisted Solution

Scay7 earned 300 total points
ID: 16975609
After some seconds (~ 90000, almost a day) it pop up a message sayint "integer overflow"

This part where it works out the seconds, mabey you assigned a value as byte rather then int64 or longint
mabey its those counting of seconds thats causing the error :P

Just a thought...

Peace Scay7
LVL 11

Assisted Solution

ZhaawZ earned 300 total points
ID: 16978050
>> just change the data type from integer to longint; or int64
atul_parmar, I'm not sure about "new" Delphi versions, but in D6 longint and integer were synonyms (i.e., both are 32bit signed integers, with same range –2147483648..2147483647)

About sizes (i.e., assigning 16bit value to 8bit) - shouldn't it ignore waste bits instead of throwing an error?

CodedK, I'm not sure if it helps but maybe you should remove that "on Exception do"? It would look like this:

  // do something
  // save error log

Or try using "on EIntOverflow do" instead of "on Exception do".
LVL 11

Expert Comment

ID: 16978067
Another thing you could try is using 'try .. except .. end' for whole app instead of using it only for calculations (just in case if u get overflow somewhere else).

Project -> View Source -> ...

  Application.CreateForm(TForm1, Form1);
  // save log
LVL 11

Expert Comment

ID: 16978092
And one more thing - do not use "compile and run" for testing "try .. except" stuff. Run an app without involving Delphi (or disable debugger before running an app from Delphi).
LVL 16

Author Comment

ID: 16980076
Thanks Zhaawz.
I'll give it a try without on Exception to see if it can create the log.
LVL 16

Author Comment

ID: 17002330
Thank you all for your help and sorry for the delay.
I've searched thoroughly the code to find errors. I didnt found any...

So i've replaced all integers with Int64 and the error didnt occur...
This is half measure but at least the app is running fine.
Though i cant understand why it doesnt go in the try...except when the error occur.

I will split points equally and accept atul_parmar suggestion.
Thank you.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question