Autor Beitrag
JRegier
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Mo 25.04.05 20:32 
Ich habe eine ComboBox in der Prozentzahlen stehen. Ich entferne Prozentzeichen
und Leerzeichen. So weit So gut. Aber wenn ich den String in Zahl umwandeln will
und ich habe ein "Zeichen" keine "Ziffer" eingegeben, bleibt das Programm hängen.

Ich habe das ganze in ein try except Block gelegt - schützt es nicht davor?
In Java ist es kein Problem!

Welche Funktion gibts in Delphi die mir komplet ein String prüft aob das eine Zahl ist?
oder muß ich mir etwa eine selber schreiben? Wenn ja ich habe es versucht
und zwar kann man in Delphi einfach ein String mit s[i] ansprechen um auf einzelne Zeichen zu
prüfen? Ich habe es zwar mit

ausblenden Quelltext
1:
2:
if(s[i] < '0') or (s[i] > '9') then
isNumeric := False;


probiert. Aber es klappte nicht. Ich weiß nicht genau ob '0' im ASCII Zeichensatz zuerst
kommt oder die '9'; habe es auch mit (s[i] < '1') or (s[i] > '0') klappt auch nicht.
na ja vieleicht muß ich Char(s[i]) und Char('0') machen, vieleicht kann mir jemand helfen.
Ich bin eigentlich Java Programmierer.
fvolk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 203

Win XP (Home & Pro)
Delphi 2005 Pers
BeitragVerfasst: Mo 25.04.05 20:39 
Die Prüfung auf Zahlenzeichen kannst du auch folgendermaßen realisieren:

ausblenden Delphi-Quelltext
1:
2:
if String[i] in ['0'..'9'] then
  foo(...);

_________________
Nichts auf der Welt ist so gerecht verteilt wie der Verstand. Denn jedermann ist überzeugt, dass er genug davon habe.
(René Descartes)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 25.04.05 20:45 
Guck Dir mal die Funktion StrToIntDef an ...
Die führt diese Prüfung auf Zahlen selbstständig aus ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
JRegier Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Mo 25.04.05 20:59 
user profile iconBenBE hat folgendes geschrieben:
Guck Dir mal die Funktion StrToIntDef an ...
Die führt diese Prüfung auf Zahlen selbstständig aus ...


Vielen Dank für den Tip Leute!
JRegier Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Mo 25.04.05 21:18 
user profile iconJRegier hat folgendes geschrieben:
user profile iconBenBE hat folgendes geschrieben:
Guck Dir mal die Funktion StrToIntDef an ...
Die führt diese Prüfung auf Zahlen selbstständig aus ...


Vielen Dank für den Tip Leute! Aber ich würd gern wissen wovor schützt den
try except wenn es hierbei nicht schützt. Also in Java bleibt ein Programm
bei einer Umwandlung von String zu Zahl nicht stehen. Der except Block
wird abgearbeitet und das Programm läuft weiter. Ein Pro für Java!
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mo 25.04.05 21:36 
Zitat:
Ein Pro für Java!
hättest du ihn die Hilfe geguckt wüsstest du, dass es in Delphi genauso ist,
wenn du dein Programm aber aus der IDE startest fängt Delphi die Fehler trotzdem ab und zeigt sie an (kannst du in den Optionen ausschalten).
also einfach mal außerhalb von Delphi starten um zu sehen ob's funktioniert

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
JRegier Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Mo 25.04.05 21:48 
user profile iconGSE hat folgendes geschrieben:
Zitat:
Ein Pro für Java!
hättest du ihn die Hilfe geguckt wüsstest du, dass es in Delphi genauso ist,
wenn du dein Programm aber aus der IDE startest fängt Delphi die Fehler trotzdem ab und zeigt sie an (kannst du in den Optionen ausschalten).
also einfach mal außerhalb von Delphi starten um zu sehen ob's funktioniert

mfg
GSE


Aber Delphi hat mir nicht angezeigt sondern das Programm blieb hängen!
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 25.04.05 21:57 
Wenn es sich aufhing, dann vermute ich, dass du irgendwo eine Endlosschleife gebaut hast. Da hilft auch ein try/except-Block nicht.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 25.04.05 23:41 
Nein. Delphi stoppt das programm und zeigt die stelle im quelltext, wo der fehler auftritt, und zwar stoppt es in dem moment, BEVOR das programm eine fehlermeldung bringt. wenn du es in einem try-except end; block hast, dann kommt keine fehlermeldung, wenn du das programm mit F9 weiterlaufen lässt. wenn du dies nicht tust, dann sieht es so aus, als ob 2 fehlerlmeldungen kommen würden, die eine ist allerdings von der delphi IDE. starte das programm ganz ohne delphi und schau,ob wieder ein problem auftritt.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
JRegier Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Di 26.04.05 07:58 
user profile iconMathiasSimmack hat folgendes geschrieben:
Wenn es sich aufhing, dann vermute ich, dass du irgendwo eine Endlosschleife gebaut hast. Da hilft auch ein try/except-Block nicht.


Aber natürlich, ich habe da geprüft ob unter 10% die Eingabe ist,
wenn ja dan setze ihn: ZoomBox.Text := '10%';
dadurch wiederholt sich der Vorgang onZoomBoxChange so blöd von mir hm.. :oops: