Thema: Delphi Taschenrechner Ausgabe

Einzelnen Beitrag anzeigen

Satty67

Registriert seit: 24. Feb 2007
Ort: Baden
1.566 Beiträge
 
Delphi 2007 Professional
 
#27

Re: Taschenrechner Ausgabe

  Alt 5. Jun 2009, 11:20
So ist es und die Case-Zuweisungen der Operatoren war auch nicht identisch (+ = * usw.)
Delphi-Quellcode:
function TFormTR.BerechneTerm(Formular: string): Double;
var
  Seg1,Seg2 : double;
  index : integer;
  Op : string;
  OpFound : Boolean;
begin
  OpFound := False;
  for index := 0 to 3 do begin
    case index of
      0: Op := '*';
      1: Op := '/';
      2: Op := '+';
      3: Op := '-';
    end;
    if pos(Op,Formular) > 1 then begin
      OpFound := True;
      Seg1 := BerechneTerm(copy(Formular,1,pos(Op,Formular) - 1));
      Seg2 := BerechneTerm(copy(Formular,pos(Op,Formular) + 1,length(Formular)));
      case index of
        0: Result := Seg1 * Seg2;
        1: Result := Seg1 / Seg2;
        2: Result := Seg1 + Seg2;
        3: Result := Seg1 - Seg2;
      end;
    end;
  end;

  if Not OpFound then Result := StrToFloat(Formular);
end;
Es fehlt noch Feinarbeit, nach einem Ergebnis muss neue Zahleingabe das Eingabefeld löschen usw. aber rechnen sollte er jetzt besser