Edin Hajdarevic
Edin Hajdarevic

Reputation: 112

Program keeps telling that number I wrote isn't integer

I made a program and it constantly tells me that the number I input isn't an integer.

I'm entering 100010110101 and it pops up with this error:

image

code:

procedure TForm1.Button1Click(Sender: TObject);
var
  m,lo,cshl,cdhl,cjhl,csl,cdl,cjl:integer;
begin
  m := StrToInt(Edit1.Text);
  cshl := m div 100000000000;
  cdhl := m div 10000000000 mod 10;
  cjhl := m div 10000000000 mod 100;
  csl := m div 1000000000 mod 1000;
  cdl := m div 100000000 mod 10000;
  cjl := m div 10000000 mod 100000;
  lo := cjl + cdl * 10 + csl * 100 + cjhl * 1000 + cdhl * 10000 + cshl  *100000;
  ShowMessage(IntToStr(lo));
end;

Upvotes: 1

Views: 270

Answers (1)

Vancalar
Vancalar

Reputation: 973

Consider how Delphi (and most languages) handle 32-bit integers: Wikipedia

In this context, Integer is a 32-bit integer, and any value less than -2,147,483,648 or greater than 2,147,483,647 IS NOT a valid 32-bit integer.

The "common sense" would indicate, that integers range from -∞ to +∞, but that is not the case in computer architecture.

Use Int64 if you want to "cover" more values.

In your case, the code should look like this:

var
  m,lo,cshl,cdhl,cjhl,csl,cdl,cjl:Int64;
begin
  m := StrToInt64(Edit1.Text);
  ...
end;

Cheers

Upvotes: 12

Related Questions