Autor Beitrag
volvox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Mi 23.05.07 23:41 
Hi,
ich mach was mit ner OnChange Prozedur.
Ich frage einen Zahlenwert aus einen Editfeld ab. Wenn der Benutzer das Feld jedoch ganz löscht um eine neue Zahl einzugeben, stürzt das Programm ab.
Wie kann ich meinem Programm sagen: Wenn das Editfeld leer ist, dann nimm automatisch den Wert 0?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 23.05.07 23:43 
Moin!

user profile iconvolvox hat folgendes geschrieben:
Wie kann ich meinem Programm sagen: Wenn das Editfeld leer ist, dann nimm automatisch den Wert 0?

Eine Möglichkeit:
ausblenden Delphi-Quelltext
1:
Value := StrToIntDef(Edit1.Text,0);					

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Do 24.05.07 14:40 
Ich habs noch nicht ganz verstanden und es kommt immer noch ein Fehler (Inkompatibel Typen String und Integer)

Ich habs mal so versucht:

edtKundensuche.Text := StrToIntDef(edtKundensuche.Text,0);
und so edtKundensuche.Text := StrToIntDef(StrToInt(edtKundensuche.Text),0);

Ich möchte aber einfach, dass in das Editfeld sofort ne null eingetragen wird, wenn es leer ist (mach ich mit OnCange)

aber irgendwie gehts nicht.
Kann mir jemand helfen?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 24.05.07 14:48 
Moin!

user profile iconvolvox hat folgendes geschrieben:
Ich möchte aber einfach, dass in das Editfeld sofort ne null eingetragen wird, wenn es leer ist

Hm, vielleich einfach mal das: :?
ausblenden Delphi-Quelltext
1:
2:
if (edtKundensuche.Text = ''then
  edtKundensuche.Text := '0';


cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Do 24.05.07 14:51 
sicher^^, einfach aber simpel. danke
FiceGoesDelphi
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 485

Win XP Prof
Delphi 2006
BeitragVerfasst: Do 24.05.07 15:05 
user profile iconvolvox hat folgendes geschrieben:
sicher^^, einfach aber simpel. danke


Einfach = Simpel ?! *gg*


Aber schreibe es am besten so...

ausblenden Delphi-Quelltext
1:
2:
if Trim(edtKundensuche.Text = ''then  
  edtKundensuche.Text := '0';


Ich glaube nämlich, dass er bei einem "leerzeichen" es nicht als '' erkennen würde!
Mit dem Trim ignorierst du sozusagen die Leerzeichen am Anfang eines "Textes".
Aber alles ohne Gewähr :P

_________________
<(^^<) <(^^)> (>^^)>
===================