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 spResult(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 spResult(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 := spResult(Copy(ATerm, 1, iPos - 1));
Value2 := spResult(Copy(ATerm, iPos + 1, Length(ATerm)));
case i
of
0: spResult := Value1 + Value2;
1: spResult := Value1 - Value2;
2: spResult := Value1 * Value2;
3: spResult := Value1 / Value2;
end;
Exit;
end;
end;
spResult := StrToFloat(ATerm);
end;