Autor Beitrag
delphistart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119



BeitragVerfasst: Do 07.02.08 22:49 
Hallo, ich habe folgendes Problem:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
  var s:string;
  z:longint;
begin
  z:=12345;  
  s:='4502009720';
  z:=z+StrToInt(s);
end;


In der letzten Zeile tritt folgender Fehler auf: '4502009720' ist kein gültiger Integerwert.

Das ist logisch, denn der Wert ist ja zu hoch, aber wie kann ich einen String zu Longint umwandeln und so die berechnung fehlerfrei durchführen?
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Do 07.02.08 22:53 
Nimm StrToInt64, dann sollte das funktionieren.

Deine Variable solltest du auch als Int64 deklarieren, da der Zahlenwert für LongInt bzw. Integer zu groß ist (LongInt und Integer sind identische 32-Bit-Datentypen und gehen deshalb von -2^31 bis 2^31-1).
delphistart Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119



BeitragVerfasst: Do 07.02.08 23:11 
Vielen Dank!

Das war die "Rettung"!!! :dance2:
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Do 07.02.08 23:37 
Biddeschön 8)
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 08.02.08 05:52 
Um es ganz fehlerfrei abzusichern, empfehle ich entweder einen try..except..end-Abschnitt, oder die TryStrToInt - Variante. Sollte auch für 64 bit existieren.

_________________
Es gibt keine Probleme - nur Lösungen!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 08.02.08 06:38 
Noch besser wäre TryStrToInt() oder Val().

_________________
Markus Kinzler.