unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Buttons;
type
{ TForm1 }
TForm1 = class(TForm)
Label1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Tsb0: TSpeedButton;
Tsb01: TSpeedButton;
Tsb02: TSpeedButton;
Tsb03: TSpeedButton;
Tsb04: TSpeedButton;
Tsb05: TSpeedButton;
Tsb06: TSpeedButton;
Tsb07: TSpeedButton;
Tsb08: TSpeedButton;
Tsb09: TSpeedButton;
TsbClear: TSpeedButton;
TsbDivision: TSpeedButton;
TsbMultiplication: TSpeedButton;
TsbSubtraction: TSpeedButton;
TsbAddition: TSpeedButton;
TsbEqual: TSpeedButton;
procedure TsbClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TsbOpClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
number,result: real;
math_op : boolean;
zeichen, op, current_op : char;
zeichenkette : ansistring;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.TsbClick(Sender: TObject);
begin
if Sender is TSpeedButton then
if Sender = Tsb0 then zeichen := '0';
if Sender = Tsb01 then zeichen := '1';
if Sender = Tsb02 then zeichen := '2';
if Sender = Tsb03 then zeichen := '3';
if Sender = Tsb04 then zeichen := '4';
if Sender = Tsb05 then zeichen := '5';
if Sender = Tsb06 then zeichen := '6';
if Sender = Tsb07 then zeichen := '7';
if Sender = Tsb08 then zeichen := '8';
if Sender = Tsb09 then zeichen := '9';
if math_op = true
then
begin
math_op:= false;
zeichenkette := zeichen;
end
else zeichenkette := zeichenkette + zeichen;
label1.Caption := zeichenkette;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
math_op := true;
current_op := '0';
end;
procedure TForm1.TsbOpClick(Sender: TObject);
begin
if Sender is TSpeedButton then
if Sender = TsbAddition then op := '1';
if Sender = TsbSubtraction then op := '2';
if Sender = TsbMultiplication then op := '3';
if Sender = TsbDivision then op := '4';
if Sender = TsbClear then op := 'c';
if Sender = TsbEqual then op := '=';
math_op := true;
number := strtofloat(label1.Caption);
if current_op = '0' then result := number;
if current_op = '1' then result := result+number;
if current_op = '2' then result := result-number;
if current_op = '3' then result := result*number;
if current_op = '4' then result := result/number;
if current_op = 'c' then result := 0;
if current_op = '=' then result := result;
current_op := op;
label1.Caption := floattostr(result);
end;
end.