Autor Beitrag
Krefti
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 26.02.08 16:05 
Hi zusammen..

hab eine kurze frage.

wie überprüfe ich Variablen, die als double deklariert sind, ob auch wirklich eine Gleitkommazahl drin steht? die Eingabe der Werte funktioniert über ein Editfeld.
hab auch noch ein paar integer variablen, die ich auch noch überprüfen möchte. da hätt ich die gleiche frage.
danke schon mal im voraus!!
gruß Krefti
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 26.02.08 16:16 
In einer Variable vom Typ double kann auch nur eine Gleitkommazahl drin sein, ich verstehe nicht ganz was du meinst.
Meinst du, ob 0 drin steht? Oder meinst du, du möchtest feststellen, ob im Editfeld eine Zahl drin steht?
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Di 26.02.08 16:18 
wenn du mir sagst, wie ich ein 'A' in einen double-Datentyp schreiben kann, sag ich dir, wie man das prüft, ob da ne Zahl drin steht :D

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 26.02.08 16:23 
hab mich wohl etwas falsch ausgedrückt..
ich möchte die eingabe in dem edit überprüfen, auf richtige eingabe, buchstaben und sonderzeichen habe ich abgefangen, mit dem onkeypress, aber kommas können doch z.b. auch eingegeben werden, was mach ich wenn jemand z.b. 45,4,234 eingibt?? da bekomm ich ja eine exception, hab gehört da gibts irgendwas mit value?? weiß aber net, wie ich des verwenden kann..
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Di 26.02.08 16:28 
Wenn Du alle falsche Eingaben mit OnKeyPress abfängst, warum dann nicht auch ein zweites Komma?
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 26.02.08 16:33 
user profile iconNico72 hat folgendes geschrieben:
Wenn Du alle falsche Eingaben mit OnKeyPress abfängst, warum dann nicht auch ein zweites Komma?



ich habs so geschrieben..
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm2.Keypress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9',',', #8]) then begin
    showmessage('Sie dürfen nur Zahlen eingeben!');
    key := #0;
    exit;
  end;
end;


damit erlaube ich ja das ',' also darf es auch 2 mal eingegeben werden wie kann ich des abfangen?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 26.02.08 16:38 
Tipp:
Wenn jemand ein Komma eintippt, überprüfst du vorher, ob schon eins drin ist (Stichwort: pos() ).
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Di 26.02.08 16:41 
Du überprüfst, ob schon ein Komma im Text vorkommt, und wenn ja, löscht du auch Key.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 26.02.08 16:41 
Nebenbei: Wofür das exit am Ende der Prozedur?
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 26.02.08 16:56 
user profile iconNico72 hat folgendes geschrieben:
Du überprüfst, ob schon ein Komma im Text vorkommt, und wenn ja, löscht du auch Key.

und wie schreib ich des? steh grad etwas aufm schlauch..

@marc, ja exit is unnötig..
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Di 26.02.08 17:04 
Hast du denn mal nach Pos() gesucht, wie es Xentar vorgeschlagen hat?
Krefti Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

Win XP/Vista/Win7/ubuntu
Delphi 7/2006/2009 Pro
BeitragVerfasst: Di 26.02.08 17:07 
user profile iconNico72 hat folgendes geschrieben:
Hast du denn mal nach Pos() gesucht, wie es Xentar vorgeschlagen hat?


ja, aber ich weiß net genau wie ich des verwenden soll..wird des im onkey verwendet oder da wo dann des vom edit.text in die variable geschrieben wird?

kann ich mir val() nur integer eingaben überprüfen?
Nico72
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50

Win XP, Vista
Delphi 7, Delphi 2006
BeitragVerfasst: Di 26.02.08 17:12 
Ich würde falsche Eingaben schon gar nicht erlauben, also die Eingaben im OnkeyPress abfangen. So wie du es ja auch schon angefangen hast. Wenn ein Komma eingegeben wird, musst du nur noch mit POS abfragen, ob im Text schon ein Komma vorhanden ist, und wenn ja, Key auch auf #0 setzen.