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 FormCreate(Sender: TObject);
procedure SpZahlClick(Sender: TObject);
procedure SpZeichenClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure spResultClick(Sender: TObject);
private
{ Private-Deklarationen }
op : char;
SpArray :
ARRAY[0..9]
OF TSpeedButton;
public
{ Public-Deklarationen }
end;
var
FormTR: TFormTR;
implementation
{$R *.DFM}
procedure TFormTR.FormCreate(Sender: TObject);
begin
SpArray [0] := Sp0;
SpArray [1] := Sp1;
SpArray [2] := Sp2;
SpArray [3] := Sp3;
SpArray [4] := Sp4;
SpArray [5] := Sp5;
SpArray [6] := Sp6;
SpArray [7] := Sp7;
SpArray [8] := Sp8;
SpArray [9] := Sp9;
end;
procedure TFormTR.SpeedButton1Click(Sender: TObject);
begin
LabelAnzeige.Caption := '
0';
end;
procedure TFormTR.spResultClick(Sender: TObject);
var Formular,Seg1,Seg2:
string;
index : integer;
Op :
string;
begin
Formular := LabelAnzeige.Caption;
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
Seg1 := copy(Formular,1,pos(Op,Formular) - 1);
Seg2 := copy(Formular,pos(Op,Formular) + 1,length(Formular));
end;
end;
ShowMessage(Seg1+Op+Seg2);
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.