Autor Beitrag
toxicmaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Sa 05.02.05 13:08 
hi,
was ist hier falsch, wenn ich die rechnung nur durchführen will, wenn edit1 und 2 größer als 0 sind.
Also es soll erst gerechnet werden, wenn die vorraussetzung gegeben ist.

hier der quelltext:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Bt1Click(Sender: TObject);
begin
  if ed1.text>0 and ed2.Text>0 then
  begin
    try
    ed3.Text:=floattostr(strtofloat(ed1.Text)+strtofloat(ed2.Text));
    except
    bt2click (sender);
    end;
  end;
end;


das wird mir als fehler angezeigt:
[Fehler] Unit1.pas( 38 ): Inkompatible Typen: 'String' und 'Integer'


Moderiert von user profile iconChristian S.: Topic aus Sonstiges verschoben am Sa 05.02.2005 um 13:12
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 05.02.05 13:12 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Bt1Click(Sender: TObject);
begin
  if (strtofloat(ed1.text)>0) and (strtofloat(ed2.Text)>0) then
    try
      ed3.Text:=floattostr(strtofloat(ed1.Text)+strtofloat(ed2.Text));
    except
      bt2click (sender);
    end;
end;

Denk dran, auch für ed1 und ed2 eine Verifizierung einzubauen!
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 05.02.05 13:13 
ausblenden Delphi-Quelltext
1:
if ed1.text>0 and ed2.Text>0 then					


muss sein:

ausblenden Delphi-Quelltext
1:
if (strtofloat(ed1.text>0)) and (strtofloat(ed2.Text>0)) then					


aber gewöhn dir bitte

ausblenden Delphi-Quelltext
1:
if ( (strtofloat(ed1.text > 0)) and (strtofloat(ed2.Text > 0)) ) then					


an. dann haste später keine probs wenn andere programmiersprache lernen willst


Zuletzt bearbeitet von uall@ogc am Sa 05.02.05 13:21, insgesamt 1-mal bearbeitet
toxicmaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Sa 05.02.05 13:14 
okay danke hat geklappt.
hatte das selbe probiert ging bei mir aber nicht, weil ich das >0 auch mit in die klammer von dem ed genommen hab.

edit:
hä das zweite von dir hatte ich glaube ich prbiert und es ging nicht.
mom teste es mal.

sag ich ja das zweite geht nicht weil das >0 auch in der klammer ist und dann kommt wieder der str int fehler.

als nächstes will ich jetzt mit else noch etwas einbauen.
nämlich, es soll abgefragt werden ob was im edit steht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Bt1Click(Sender: TObject);
begin
  if (strtofloat(ed1.text)>0) and (strtofloat(ed2.Text)>0) then
  begin
    try
    ed3.Text:=floattostr(strtofloat(ed1.Text)+strtofloat(ed2.Text));
    except
    bt2click (sender);
    end;
  end;
end;

ausblenden Delphi-Quelltext
1:
2:
if (strtofloat(ed1.text)('')) and (strtofloat(ed2.Text)('')) then
begin

kann ich das noch als else einfügen?

Moderiert von user profile iconraziel: 3 (!) Beiträge zusammengefasst.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 05.02.05 13:24 
habs geändert

du solltest alle ausdrücke um eine verknüpfung AND / OR in klammern setzen und nochmal den ganzen zwischen IF und THEN
in java oder c++ muss man das amchen also gewöhns dir an ;>

if (bla) blub ist z.b. bei java gültig da das then fehlt und die if abfrage für 1 klammer gilt
if bla { blub } geht z.b. nicht da keine klammer folgt

if (bla == 1 && bla2) {blub} geht auch nicht

aber if ( (bla == 1) && bla2) blub geht wieder

//Edit: ja nach dem vorletzen END; ein END ELSE

Moderiert von user profile iconChristian S.: Beiträge zusammengefügt, bitte Edit-Funktion nutzen
toxicmaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Sa 05.02.05 13:27 
ne aber dann hat er die rechnung doch schon gemacht und ich kann nicht mehr über prüfen ob die edits überhaupt gefüllt sind.
iw wollte es vor der rechnung haben.

also es soll ungefähr so sein. aber das geht nicht, da in der neuen zeile angeblich ein simikolon fehlt.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Bt1Click(Sender: TObject);
begin
  if (strtofloat(ed1.text)>0) and (strtofloat(ed2.Text)>0) then
  else
  if (strtofloat(ed1.text)('')) and (strtofloat(ed2.Text)('')) then
  begin
    try
    ed3.Text:=floattostr(strtofloat(ed1.Text)+strtofloat(ed2.Text));
    except
    bt2click (sender);
    end;
  end;
end;


Moderiert von user profile iconraziel: Wieder 2 Beiträge zusammengefasst. Bitte künftig die Edit-Funktion benutzen :mahn:
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 05.02.05 13:31 
ausblenden Delphi-Quelltext
1:
if (strtofloat(ed1.text)('')) and (strtofloat(ed2.Text)('')) then					


das eh kein gültiger aufruf, wen ndu schaun willst ob der text leer ist machs so:

ausblenden Delphi-Quelltext
1:
2:
if ((ed1.text <> '') and (ed2.text <> '')) then
  if (stroto....)
toxicmaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Sa 05.02.05 13:36 
das klappt nicht, denn wenn man jetzt auch berechnen drückt und es nichts in die felder eingeben wurden, dann kommt die fehlermeldung, " kein gültiger Gleitkommawert.

ausblenden Delphi-Quelltext
1:
if (stroto....)					

muss das auch rein, wenn ja dann ist das mein prob, da ich keine ahnung hab was das machen soll.
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Sa 05.02.05 13:44 
nein da sist deine if abfrage oO
du pakcst meine einfach vor das was du jetzt hast
toxicmaster Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Sa 05.02.05 13:46 
gut das habe ich mir schon gedacht.
habe aber nen else dazwichen gehabt und das ging nicht.
wenn es weg ist geht es. danke :lol: