Autor Beitrag
Jukka
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Fr 01.09.06 15:38 
Hallo

Ich möchte fragen ob es möglich ist herrauszufinden ob inttostr möglich ist. Ich habe schon einiges versucht, jedoch bekomm ich wenn es nicht möglich ist immer eine Meldung "xxxxxx ist kein gültiger Integer Wert"

Kann man da etwas machen?

MfG Ju
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 01.09.06 15:42 
Du kannst z.B.
  • in einer Schleife durchgehen, ob MeinString[i] nicht in 0..9 ist (das erste Zeichen darf auch '-' oder '+' sein) oder
  • um StrToInt einen Try-Except-Block drummachen, so dass die Exception abgefangen wird oder
  • StrToIntDef benutzen

_________________
We are, we were and will not be.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 01.09.06 15:47 
Du meinst wohl eher StrToInt. Inttostr geht immer!
Ansonsten zu deiner Frage:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var dummy:integer;
begin
  if TryStrToInt('abc',dummy) then
   //nie ausgeführt


Wenn es klappt, steht in Dummy der Wert drin.

//Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Jukka Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Fr 01.09.06 16:01 
Ja entschuldigung war mein fehler, meinte ich natürlich

StrToIntDef geht wunderbar danke ^^
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 01.09.06 17:30 
wobei ein integer ja auch den angegebenen wert haben kann und dass dann in 1 / (2*maxint) aller fälle zum problem wird.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 01.09.06 17:37 
Solange man den Rückgabewert von TryStrToInt verarbeitet, anstatt zu prüfen ob der "Platzhalterwert" herausgekommen ist, sollte man da kein Problem bekommen.

Ansonsten kann man auch noch die Prozedur "Val" verwenden, die sagt einem sogar das Zeichen, welches nicht gepasst hat ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".