unit Calculator_Main;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Buttons, StdCtrls;
type
TFormTR =
class(TForm)
Sp7: TSpeedButton;
Sp8: TSpeedButton;
Sp9: TSpeedButton;
Sp4: TSpeedButton;
Sp5: TSpeedButton;
Sp6: TSpeedButton;
Sp1: TSpeedButton;
Sp2: TSpeedButton;
Sp3: TSpeedButton;
Sp0: TSpeedButton;
DecimalSep: TSpeedButton;
spResult: TSpeedButton;
SpPlus: TSpeedButton;
SpMinus: TSpeedButton;
SpMal: TSpeedButton;
SpDurch: TSpeedButton;
LabelAnzeige: TLabel;
SpeedButton1: TSpeedButton;
procedure SpZahlClick(Sender: TObject);
procedure SpZeichenClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
function TFormTR.BerechneTerm(ATerm:
string): Double;
private
{ Private-Deklarationen }
op : char;
public
{ Public-Deklarationen }
end;
var
FormTR: TFormTR;
implementation
{$R *.DFM}
procedure TFormTR.SpeedButton1Click(Sender: TObject);
begin
LabelAnzeige.Caption := '
0';
end;
function TFormTR.BerechneTerm(ATerm:
string): Double;
var
Op:
string;
iPos, i: Integer;
Value1, Value2: Double;
begin
for i := 0
to 3
do
begin
case i
of
0: Op := '
+';
1: Op := '
-';
2: Op := '
*';
3: Op := '
/';
end;
iPos := Pos(Op, ATerm);
if iPos > 0
then
begin
Value1 := BerechneTerm(Copy(ATerm, 1, iPos - 1));
Value2 := BerechneTerm(Copy(ATerm, iPos + 1, Length(ATerm)));
case i
of
0: EvaluateTerm := Value1 + Value2;
1: EvaluateTerm := Value1 - Value2;
2: EvaluateTerm := Value1 * Value2;
3: EvaluateTerm := Value1 / Value2;
end;
Exit;
end;
end;
EvaluateTerm := StrToFloat(ATerm);
end;
procedure TFormTR.SpZahlClick(Sender: TObject);
begin
if LabelAnzeige.caption='
0'
then LabelAnzeige.caption:='
';
if LabelAnzeige.caption='
Error'
then LabelAnzeige.caption:='
';
LabelAnzeige.caption := LabelAnzeige.caption + TSpeedButton(Sender).Caption;
end;
procedure TFormTR.SPZeichenClick(Sender: TObject);
begin
if LabelAnzeige.caption='
Error'
then LabelAnzeige.caption:='
0';
if sender = spPlus
then
begin
op:='
+'
end;
if sender = spMinus
then
begin
op:='
-'
end;
if sender = spMal
then
begin
op:='
x'
end;
if sender = spDurch
then
begin
op:='
/'
end;
LabelAnzeige.caption := LabelAnzeige.caption + op;
end;
end.