unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus;
type
TForm1 =
class(TForm)
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;
Label1: TLabel;
Button17: TButton;
Button18: TButton;
procedure Button18Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure ZeiButtonClick(Sender: TObject);
procedure OpButtonClick(Sender: TObject);
procedure IstButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Hilfe2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var strBuff1, strBuff2:
string;
// Operanden- u. Ergebnisspeicher
op: Char;
// Operation (+,-,*,/)
mode: Byte = 1;
// 1 = ersten Operand eingeben
// 2 = zweiten Operand eingeben
procedure TForm1.Button17Click(Sender: TObject);
// Anzeige löschen
begin
if mode = 1
then StrBuff1 := '
'
else StrBuff2 := '
';
Label1.Caption := '
'
end;
procedure TForm1.ZeiButtonClick(Sender: TObject);
// Zahleneingabe
var zei: Char;
// eingegebenes Zeichen
begin
if Sender = Button10
then zei := '
0';
if Sender = Button1
then zei := '
1';
if Sender = Button2
then zei := '
2';
if Sender = Button3
then zei := '
3';
if Sender = Button4
then zei := '
4';
if Sender = Button5
then zei := '
5';
if Sender = Button6
then zei := '
6';
if Sender = Button7
then zei := '
7';
if Sender = Button8
then zei := '
8';
if Sender = Button9
then zei := '
9';
if Sender = Button11
then zei := '
.';
if mode = 1
then
begin
strBuff1 := strBuff1 + zei;
Label1.Caption := strBuff1
end else
begin
strBuff2 := strBuff2 + zei;
Label1.Caption := strBuff2
end
end;
procedure TForm1.OpButtonClick(Sender: TObject);
// Operation auswählen
begin
if mode = 1
then
begin
if Sender = Button14
then op:= '
+';
if Sender = Button15
then op:= '
-';
if Sender = Button12
then op:= '
*';
if Sender = Button13
then op:= '
/';
StrBuff2:='
';
mode := 2
end
end;
procedure TForm1.IstButtonClick(Sender: TObject);
// Ergebnis berechnen
var res, op1, op2: Double;
code: Integer;
s:
string;
begin
if mode = 2
then
begin
Val(strBuff1, op1, code);
// StringBuffer1 in Zahl verwandeln
Val(strBuff2, op2, code);
// StringBuffer2 in Zahl verwandeln
case op
of // Operation durchführen
'
+': res:= op1 + op2;
'
-': res := op1 - op2;
'
*': res := op1 * op2;
'
/': res := op1 / op2
end;
s:= Format('
%g',[res]);
// Ergebnis formatieren
Label1.Caption := s;
// ... und anzeigen
mode := 1;
strBuff1 := '
'
end
end;
procedure TForm1.Button18Click(Sender: TObject);
// Rechner ausschalten
begin
Close
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.HelpFile := '
Taschenrechner.hlp'
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
Application.HelpJump('
Inhalt')
end;
procedure TForm1.Hilfe2Click(Sender: TObject);
begin
Application.HelpJump('
Inhalt')
end;
end.