Autor Beitrag
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: So 23.09.07 14:14 
Hey,

ich hab heute ein Programm zum errechnen eines Kaufpreises(MWSt, Dollar, Yen etc ) geschrieben.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Edit2Change(Sender: TObject);
var
e, z, mwst, summe : Real ;
begin
edit3.text := FloatToStr((StrToFloat(edit1.text)+ StrToFloat(edit2.text))*1.19) ;
end;


procedure TForm1.Edit3Change(Sender: TObject);
begin
edit4.Text := FloatToStr((StrToFloat(edit3.text))*1.40) ;
edit5.Text := FloatToStr((StrToFloat(edit3.text))*152.74) ;
end;

procedure TForm1.Be1Click(Sender: TObject);
begin
Form1.Close ; 
end;

procedure TForm1.Minimieren1Click(Sender: TObject);
begin
Application.Minimize ;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 with form1 do 
  BorderStyle := bsSingle;
  BorderIcons := [biSystemMenu];
end;

end.


jetzt habe ich das Problem wenn ich mal keine Zahl im edit2. eigeben will, bekomme ich logischer Weise die Fehlermeldung, das es keine gültige zahl ist. Wie kann ich diesem Edit Feld zu verstehen geben, das es auch mit keiner eingabe zurecht kommen soll !


Grüße

GericasS

Moderiert von user profile iconNarses: Titel angepasst: Komponentenname korrigiert

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 23.09.07 14:19 
Probier es mal mit StrToFloatDef(); ;)

grüße,
Marc
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: So 23.09.07 20:03 
Bzw. TryStrToFloat

_________________
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.
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 24.09.07 06:34 
Hey,

danke für den tollen Tipp hat auch sehr gut funktioniert habe es jetzt wie folgt gecoded

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Edit2Change(Sender: TObject);
var
e, z, mwst, summe : Real ;
begin
edit3.text := FloatToStr((StrToFloat(edit1.text)+ StrToFloat(edit2.text))*1.19) ;
end;


procedure TForm1.Edit3Change(Sender: TObject);
begin
edit4.Text := FloatToStr((StrToFloatDef(edit3.text, 0))*1.40) ;
edit5.Text := FloatToStr((StrToFloatDef(edit3.text, 0))*152.74) ;
end;

procedure TForm1.Be1Click(Sender: TObject);
begin
Form1.Close ; 
end;

procedure TForm1.Minimieren1Click(Sender: TObject);
begin
Application.Minimize ;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 with form1 do 
  BorderStyle := bsSingle;
  BorderIcons := [biSystemMenu];
end;

end.


Aber wenn ich jetzt keine Zahl eingebe, bekomme ich ja diesen exception error,
kann ich dies auffangen, wenn ich einfach

try

except


nutzte ?

Grüße !

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 24.09.07 07:06 
wie wäre es mit:

ausblenden Delphi-Quelltext
1:
2:
if length(edit1.text)>0 then
  {...}


lg elundril
GericasS Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Mo 24.09.07 07:29 
user profile iconelundril hat folgendes geschrieben:
wie wäre es mit:

ausblenden Delphi-Quelltext
1:
2:
if length(edit1.text)>0 then
  {...}


lg elundril


Macht das nicht auch Probleme wenn ich im edit Feld keine Eingabe tätige ?
Weil das würde dann nur passen bei 0 oder ?

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 24.09.07 07:31 
glaub nicht weil er ja nur die länge überprüft.

der code sagt: wenn die länge vom text der eingegeben wurde größer als null ist dann versuche den text in eine zahl zu verwandeln.

lg elundril
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mo 24.09.07 07:31 
Dafür ist doch StrToFloatDef gedacht, Du musst es dann aber auch auf deine anderen Eingabefelder anwenden.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)