Autor Beitrag
wunsiedler
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 506
Erhaltene Danke: 4

Win7

BeitragVerfasst: Mi 03.09.03 16:09 
Wie kann ich prüfen, ob in "Edit1.Text" eine gültige Zahl steht, bevor ich diese mit " StrToFloat" umwandle. Steht da eine ungültige, kommt eine eceptions, was ich vermeiden will.
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mi 03.09.03 16:10 
Es gibt in der Unit IdGlobal eine Funktion IsNumeric.

Du kannst aber auch einen try...except Block um deine Typumwandlung schreiben.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
wunsiedler Threadstarter
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 506
Erhaltene Danke: 4

Win7

BeitragVerfasst: Mi 03.09.03 16:29 
Zitat:
[Error] Unit1.pas(29): Undeclared identifier: 'isnumeric'

Das sagt er mir bei IsNumeric
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if(isnumeric(Edit1.Text))then
begin
.............
end;

D6 PE, WIN2000

Moderiert von user profile iconTino: Delphi- & Quote-Tags hinzugefügt.
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Mi 03.09.03 20:40 
Deshalb hat dir derDoc ja auch mitgeteilt, daß das in der Unit idGlobal enthalten ist. Diese Unit solltest Du dann natürlich auch in deine Uses Liste mit aufnehmen.

ABER: derDoc ist leider auf dem Holzweg. IsNumeric(c: Char): Boolean !!! Also leider nur für einzelne Zeichen anwendbar.

Die Einbindung in ein Try ... Except ... End; würde ich bevorzugen. (Und nicht wundern, daß beim Testlauf in der Delphi-IDE nach wie vor eine Fehlermeldung kommt. Eine weitere Möglichkeit wäre StrToFloatDef. Da kannst einen Standardwert setzen, der zurückgegeben wird, wenn die Umwandlung zu einem Fehler führt.

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
Brueggendiek
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 304

Win 98, Win98SE, Win XP Home
D5 Std
BeitragVerfasst: Mi 03.09.03 21:54 
Hallo!

Wesentlich schneller als mit dem TRY-EXCEPT geht es mit Val! Ist der Code 0, war alles klar.

Gruß

Dietmar Brüggendiek