Autor Beitrag
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Sa 21.10.06 15:15 
Hi allerseits,
hab' mal wieder 'ne Frage bzgl. Konsolenanwendungen. Es gibt viele Möglichkeiten wie man bei (Visual) Delphi überprüfen kann, ob in einem Edit-Feld, in dem ein Integer-Wert stehen soll, auch wirklich ein Integer-Wert steht.
Wie geht das bei einer Konsolenanwendung, für folgenden Fall:

ausblenden Delphi-Quelltext
1:
2:
writeln('Bitte einen gültigen Integer-Wert eingeben: ');
readln(intvalue); // var intvalue : integer;


Wenn nun Buchstaben oder floating-Werte eingegeben werden, schmeißt mich das Programm natürlich raus. Das will ich unterbinden.

Gruß
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: Sa 21.10.06 15:55 
Du kannst mit Readln(StringVal) einlesen und dann mit Val konvertieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var str:string;
    i,e:integer;

begin
  Readln(str);
  Val(Str,i,e);
  if e>0 then
    //hau den User....
  else
    MachWasMit(i);
end.

_________________
"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."
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Sa 21.10.06 16:08 
Funktioniert wunderbar!

Vielen Dank!

Gruß