计算器(思想)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
edt1: TEdit;
btn1: TButton;
btn2: TButton;
btn3: TButton;
btn4: TButton;
btn5: TButton;
btn6: TButton;
btn7: TButton;
btn8: TButton;
btn9: TButton;
btn10: TButton;
btn11: TButton;
btn12: TButton;
btn13: TButton;
btn14: TButton;
btn15: TButton;
btn16: TButton;
btn17: TButton;
procedure FormCreate(Sender: TObject);
procedure btn17Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure btn6Click(Sender: TObject);
procedure btn7Click(Sender: TObject);
procedure btn8Click(Sender: TObject);
procedure btn10Click(Sender: TObject);
procedure btn11Click(Sender: TObject);
procedure btn12Click(Sender: TObject);
procedure btn15Click(Sender: TObject);
procedure btn14Click(Sender: TObject);
procedure btn4Click(Sender: TObject);
procedure btn5Click(Sender: TObject);
procedure btn9Click(Sender: TObject);
procedure btn13Click(Sender: TObject);
procedure btn16Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
op:Char;
fg:Boolean;
nm:Double;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
op:='a';
fg:=False;
nm:=0;
end;
procedure TForm1.btn17Click(Sender: TObject);
begin
edt1.Text:='';
op:='a';
fg:=False;
nm:=0;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='1';
end else
edt1.Text:=edt1.Text+'1';
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='2';
end else
edt1.Text:=edt1.Text+'2';
end;
procedure TForm1.btn3Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='3';
end else
edt1.Text:=edt1.Text+'3';
end;
procedure TForm1.btn6Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='4';
end else
edt1.Text:=edt1.Text+'4';
end;
procedure TForm1.btn7Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='5';
end else
edt1.Text:=edt1.Text+'5';
end;
procedure TForm1.btn8Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='6';
end else
edt1.Text:=edt1.Text+'6';
end;
procedure TForm1.btn10Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='7';
end else
edt1.Text:=edt1.Text+'7';
end;
procedure TForm1.btn11Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='8';
end else
edt1.Text:=edt1.Text+'8';
end;
procedure TForm1.btn12Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='9';
end else
edt1.Text:=edt1.Text+'9';
end;
procedure TForm1.btn15Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='0';
end else
edt1.Text:=edt1.Text+'0';
end;
procedure TForm1.btn14Click(Sender: TObject);
begin
if fg=True then
begin
nm:=StrToCurr(edt1.Text);
edt1.Text:='';
fg:=False;
edt1.Text:='0.';
end else
edt1.Text:=edt1.Text+'.';
end;
procedure TForm1.btn4Click(Sender: TObject);
begin
case op of
'+':
edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
'-':
edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
'*':
edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
'/':
edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
// else
// edt1.Text:=edt1.Text;
end;
fg:=True;
op:='+';
end;
procedure TForm1.btn5Click(Sender: TObject);
begin
case op of
'+':
edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
'-':
edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
'*':
edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
'/':
edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
// else
// edt1.Text:=edt1.Text;
end;
fg:=True;
op:='-';
end;
procedure TForm1.btn9Click(Sender: TObject);
begin
case op of
'+':
edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
'-':
edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
'*':
edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
'/':
edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
// else
// edt1.Text:=edt1.Text;
end;
fg:=True;
op:='*';
end;
procedure TForm1.btn13Click(Sender: TObject);
begin
case op of
'+':
edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
'-':
edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
'*':
edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
'/':
edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
// else
// edt1.Text:=edt1.Text;
end;
fg:=True;
op:='/';
end;
procedure TForm1.btn16Click(Sender: TObject);
begin
case op of
'+':
edt1.Text:=CurrToStr(nm+StrToCurr(edt1.Text));
'-':
edt1.Text:=CurrToStr(nm-StrToCurr(edt1.Text));
'*':
edt1.Text:=CurrToStr(nm*StrToCurr(edt1.Text));
'/':
edt1.Text:=CurrToStr(nm/StrToCurr(edt1.Text));
// else
// edt1.Text:=edt1.Text;
end;
nm:=0;
fg:=True;
end;
end.