Autor Beitrag
soisseteben
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: So 22.10.06 11:50 
Hallo erstmal,
Ich prüfe mit folgender Methode, ob ein eingegebener Wert eine Ganzzahl darstellt:
ausblenden Delphi-Quelltext
1:
2:
3:
try
  StrToInt(Text);
except on EConvertError do ....

Dabei ergab sich das Problem, das Ausdrücke wie "xd" (=13) oder "x3" (=3) korrekt konvertiert werden können. "x" hingegen versteht StrToInt nicht als gültigen Integerwert...

Wie kann ich dieses Problem aus dem Weg räumen?

Danke schonmal.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 22.10.06 11:58 
StrToInt interpretiert Zeichenfolgen, die mit einem x beginnen, als Zahl in der Hexadezimaldarstellung. Und D(Hex) ist nunmal 13(Dec).
(btw: Warum verwechseln Informatiker ständig Halloween mit Weihnachten? - Weil 31 Okt = 25 Dec ....)

Wenn du nur die Dezimaldarstellung erlauben willst, musst du wohl was eigenes basteln:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function isDezimalZahl(aString: String): boolean;
var i: integer;
begin
  if aString = '' then result := false
  else 
  begin
    result := true;
    for i := 1 to length(aString) do
      if not aString[i] in [0..9then
      begin
        result := false;
        break; 
      end;
  end;
end;

_________________
We are, we were and will not be.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 22.10.06 12:01 
Kleine Gegenfrage, was soll den x als Integer darstellen? 10 (röm.)?

_________________
Markus Kinzler.
soisseteben Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: So 22.10.06 12:05 
Danke! :D

_________________
„Wer nur nach dem Zweck der Dinge fragt, wird ihre Schönheit nie entdecken.“ - (Halldór Laxness)
soisseteben Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: So 22.10.06 12:16 
Ähm, ich war wohl etwas vorschnell: bei dieser Zeile kommt die Fehlermeldung "Operator auf diesen Oparantentyp nicht anwendbar":
ausblenden Delphi-Quelltext
1:
if not aString[i] in [0..9then					


Also beim "in". Was kann man da machen :(

_________________
„Wer nur nach dem Zweck der Dinge fragt, wird ihre Schönheit nie entdecken.“ - (Halldór Laxness)
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 22.10.06 12:23 
Hallo,

ausblenden Delphi-Quelltext
1:
if not (aString[i] in ['0'..'9']) then					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 22.10.06 12:24 
oops - Probier mal if not aString[i] in ['0'..'9']

_________________
We are, we were and will not be.
soisseteben Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

Win XP
D7
BeitragVerfasst: So 22.10.06 12:42 
EDIT: Lannes hatte recht - die Klammern müssen noch rum.

Danke!