Autor Beitrag
Boerdi
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Sa 04.10.08 15:33 
Hallo,

ich habe eine Frage zu einer If Abfrage bei Edit Feldern. Ich habe dieses als Variable "double" deklariert und möchte das bei Button-Click folgendes passiert.

Wenn der Wert x überschritten wird, soll er das Editfeld zurücksetzen und eine Message anzeigen. Bisher habe ich das so gemacht und es funktioniert auch wunderbar. Allerdings nur bei Zahlen bis 99. Ab 100 kommt keine Warnung mehr.

ausblenden Delphi-Quelltext
1:
if (EBreite.Text>='75'then (showmessage('Maximalbreite erreicht'))					


Wisst ihr warum das nur bis 100 funktioniert?

MfG
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 04.10.08 15:39 
Du solltest nicht einfach Strings über den Operator >= vergleichen. Ich wusste bis jetzt nicht, dass das möglich ist...

Benutze besser TSpinEdit anstelle von TEdit, da kannst du MaxValue einstellen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 04.10.08 15:42 
Du vergleichst Zeichenketten miteinander. Und so wie "Anna" im Telefonbuch vor "Tom" kommt, steht "100" vor "75". ;-)

Abhilfe: SpinEdits oder die Strings in Zahlen umwandeln und diese vergleichen. Stichworte StrToInt, StrToFloat.

_________________
We are, we were and will not be.
Boerdi Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Sa 04.10.08 15:47 
Danke für euren schnellen Antworten. Gibt es diese TSpinEdits in der normalen Toolpalette von Turbo Delphi? Irgendwie find ich die nicht. :(

MfG
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 04.10.08 15:48 
Nein, bei Turbo Delphi Explorer sind die nicht dabei. Dann nimm halt die Edits mit StrToInt. ;-)

_________________
We are, we were and will not be.
Boerdi Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Sa 04.10.08 15:55 
Sorry, dass ich nochmal nachfrage, aber wie kann ich meine If-Abfrage dann aufbauen? Bin leider noch nicht so wahnsinnig tief drin in Delphi. Meine Variable EBreite würde ich dann also zu Integer umwandeln.

Mfg
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 04.10.08 16:11 
In etwa so:
ausblenden Delphi-Quelltext
1:
if (StrToInt(EBreite.Text) >= 75then (showmessage('Maximalbreite erreicht'))					

_________________
We are, we were and will not be.
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mo 06.10.08 14:22 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
In etwa so:
ausblenden Delphi-Quelltext
1:
if (StrToInt(EBreite.Text) >= 75then (showmessage('Maximalbreite erreicht'))					

Aber bitte mit Ausnahmebehandlung! :shock:

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen