unit Rechner;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;
type
TForm1 =
class(TForm)
LabelZeichen: TLabel;
Edit: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button18: TButton;
Button19: TButton;
Button20: TButton;
Button21: TButton;
Button22: TButton;
Button23: TButton;
LabelMemory: TLabel;
EditErgebnis: TEdit;
procedure Button9Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Button20Click(Sender: TObject);
procedure Button22Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button21Click(Sender: TObject);
procedure Button23Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Backspace;
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Safemode: Boolean = false;
Memory:
String = '
';
implementation
{$R *.dfm}
procedure TForm1.Button9Click(Sender: TObject);
begin
If Edit.Text <> '
0'
then
Edit.Text := Edit.Text + '
0';
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
1'
else
Edit.Text := Edit.Text + '
1';
end;
procedure TForm1.Button20Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
2'
else
Edit.Text := Edit.Text + '
2';
end;
procedure TForm1.Button22Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
3'
else
Edit.Text := Edit.Text + '
3';
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
4'
else
Edit.Text := Edit.Text + '
4';
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
5'
else
Edit.Text := Edit.Text + '
5';
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
6'
else
Edit.Text := Edit.Text + '
6';
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
7'
else
Edit.Text := Edit.Text + '
7';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
8'
else
Edit.Text := Edit.Text + '
8';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
If Edit.Text = '
0'
then
Edit.Text := '
9'
else
Edit.Text := Edit.Text + '
9';
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
If not Safemode
then
EditErgebnis.Text := FloatToStr(StrToFloat(Edit.Text));
If not Safemode
then
Edit.Text := '
0';
Safemode := true;
LabelZeichen.Caption := '
+';
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
if not AnsiContainsText(Edit.Text,'
,')
then
Edit.Text:= Edit.Text+'
,';
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
EditErgebnis.Text := '
';
LabelZeichen.Caption := '
';
Edit.Text := '
0';
Safemode := false;
end;
procedure TForm1.Button21Click(Sender: TObject);
begin
Edit.Text := '
0';
end;
procedure TForm1.Button23Click(Sender: TObject);
begin
If not Safemode
then
EditErgebnis.Text := FloatToStr(StrToFloat(Edit.Text));
If not Safemode
then
Edit.Text := '
0';
Safemode := true;
LabelZeichen.Caption := '
-';
end;
procedure TForm1.Button17Click(Sender: TObject);
begin
If not Safemode
then
EditErgebnis.Text := FloatToStr(StrToFloat(Edit.Text));
If not Safemode
then
Edit.Text := '
0';
Safemode := true;
LabelZeichen.Caption := '
*';
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
If not Safemode
then
EditErgebnis.Text := FloatToStr(StrToFloat(Edit.Text));
If not Safemode
then
Edit.Text := '
0';
Safemode := true;
LabelZeichen.Caption := '
/';
end;
procedure TForm1.Button4Click(Sender: TObject);
var
s :
String;
begin
s := Edit.Text;
If s = '
0'
then
else if AnsiContainsText(s, '
-')
then
Delete(s,1,1)
else
s := '
-' + s;
Edit.Text := s;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
Memory := Edit.Text;
LabelMemory.Caption := '
M'
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
If Memory <> '
'
then
Edit.Text := Memory;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memory := '
';
LabelMemory.Caption := '
';
end;
procedure TForm1.Button15Click(Sender: TObject);
var
Wert1,Wert2: Extended;
Casevar: Integer;
Ergebnis:
String;
begin
Casevar := 0;
//compiler meckern umgehen
If (EditErgebnis.Text <> '
')
and (EditErgebnis.Text <> '
error')
then begin
Wert1 := StrToFloat(EditErgebnis.Text);
Wert2 := StrToFloat(Edit.Text);
If LabelZeichen.caption = '
+'
then
Casevar := 1
else If LabelZeichen.caption = '
-'
then
Casevar := 2
else If LabelZeichen.caption = '
*'
then
Casevar := 3
else If LabelZeichen.caption = '
/'
then
Casevar := 4
else If (LabelZeichen.caption = '
/')
and (Edit.Text = '
0')
then
Casevar := 5;
If (Casevar = 1)
xor (Casevar = 2)
xor (Casevar = 3)
xor (Casevar = 4)
xor
(Casevar = 5)
then begin
Case Casevar
of
1: Ergebnis := FloatToStr(Wert1 + Wert2);
2: Ergebnis := FloatToStr(Wert1 - Wert2);
3: Ergebnis := FloatToStr(Wert1 * Wert2);
4: Ergebnis := FloatToStr(Wert1 / Wert2);
5: Ergebnis := '
0';
end;
end
end;
EditErgebnis.Text := Ergebnis;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
s:
String;
begin
s := Edit.Text;
If (s <> '
0')
and (s <> '
1')
then begin
if AnsiContainsText(s, '
-')
then begin
Delete(s,1,1);
Edit.Text := FloatToStr(Sqrt(StrToFloat(s)));
end;
if s = '
1,00000000000001'
then
Edit.Text := '
1'
else
Edit.Text := FloatToStr(Sqrt(StrToFloat(s)));
end;
end;
//Problemprozedur
procedure TForm1.Backspace;
var
Str:
String;
begin
Str := Edit.Text;
If Length(Str) < 1
then
Edit.Text := Delete(Str, Length(Str), 1)
else // line 307...
Edit.Text := '
0';
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
case Key
of
VK_NUMPAD0, $30 : Button9.Click;
VK_NUMPAD1, $31 : Button19.Click;
VK_NUMPAD2, $32 : Button20.Click;
VK_NUMPAD3, $33 : Button22.Click;
VK_NUMPAD4, $34 : Button10.Click;
VK_NUMPAD5, $35 : Button13.Click;
VK_NUMPAD6, $36 : Button14.Click;
VK_NUMPAD7, $37 : Button6.Click;
VK_NUMPAD8, $38 : Button3.Click;
VK_NUMPAD9, $39 : Button5.Click;
110 : Button16.Click;
106 : Button17.Click;
107 : Button18.Click;
109 : Button23.Click;
111 : Button12.Click;
VK_RETURN : Button15.Click;
VK_BACK : Backspace;
VK_ESCAPE : close;
end;
end;
end.