delphi编写简单的计算器
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure TForm1.Button11Click(Sender: TObject);
var //n:integer;
// temp1:string;
temp2,temp3:extended;
begin
temp3:=strtofloat(edit1.Text);
begin
procedure TForm1.Button8Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'8'
else beg
in
var
Form1: TForm1;
n:integer;
temp1:extended;
key:boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if key=true
begin
if key=true
then
edit1.Text:=edit1.Text+'3'
else begin
edit1.Clear;
key:=true;
edit1.Text:='3';
end; end;
procedure TForm1.Button4Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
case n of
1:temp2:=temp1+temp3;
2:temp2:=temp1-temp3;
3:temp2:=temp1*temp3;
4:if temp3=0
then
begin
showmessage('除数不能为0!');
exit;
end
else begin
简单的计算器代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
end;
procedure TForm1.Button15Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=3;
temp1:=strtofloat(edit1.text);
edit1.Clear ;
edit1.Clear;
key:=true;
edit1.Text:='8';
end; end;
procedure TForm1.Button9Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'9'
procedure Button11Click(Sender: TObject);
procedure Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
edit1.Clear ;
end;
procedure TForm1.Button14Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=2;
temp1:=strtofloat(edit1.text);
edit1.Clear ;
begin
if key=true
then
edit1.Text:=edit1.Text+'7'
else begin
edit1.Clear;
key:=true;
edit1.Text:='7';
end; end;
temp2:=temp1/temp3;
end;
end;
edit1.text:=floattostr(temp2);
key:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
key:=true;
end;
end.
begin
edit1.clear;
end;
procedure TForm1.Button13Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=1;
temp1:=strtofloat(edit1.text);
then
edit1.Text:=edit1.Text+'0'
else begin
edit1.Clear;
key:=true;
edit1.Text:='0';
end; end;
procedure TForm1.Button12Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'4'
else begin
edit1.Clear;
key:=true;
edit1.Text:='4';
end; end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'5'
else begin
edit1.Clear;
key:=true;
edit1.Text:='5';
end; end;
procedure TForm1.Button6Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'2'
else
begin
edit1.Clear;
key:=true;
edit1.Text:='2';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
Button15: TButton;
Button16: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'6'
else begin
edit1.Clear;
key:=true;
edit1.Text:='6';
end; end;
procedure TForm1.Button7Click(Sender: TObject);
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
end;
procedure TForm1.Button16Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=4;
temp1:=strtofloat(edit1.text);
edit1.Clear;
end;
else begin
edit1.Clear;
key:=true;
edit1.Text:='9';
end; end;
procedure TForm1.Button10Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'1'
else
begin
edit1.Clear;
key:=true;
edit1.Text:='1';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure TForm1.Button11Click(Sender: TObject);
var //n:integer;
// temp1:string;
temp2,temp3:extended;
begin
temp3:=strtofloat(edit1.Text);
begin
procedure TForm1.Button8Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'8'
else beg
in
var
Form1: TForm1;
n:integer;
temp1:extended;
key:boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if key=true
begin
if key=true
then
edit1.Text:=edit1.Text+'3'
else begin
edit1.Clear;
key:=true;
edit1.Text:='3';
end; end;
procedure TForm1.Button4Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
case n of
1:temp2:=temp1+temp3;
2:temp2:=temp1-temp3;
3:temp2:=temp1*temp3;
4:if temp3=0
then
begin
showmessage('除数不能为0!');
exit;
end
else begin
简单的计算器代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
end;
procedure TForm1.Button15Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=3;
temp1:=strtofloat(edit1.text);
edit1.Clear ;
edit1.Clear;
key:=true;
edit1.Text:='8';
end; end;
procedure TForm1.Button9Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'9'
procedure Button11Click(Sender: TObject);
procedure Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
edit1.Clear ;
end;
procedure TForm1.Button14Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=2;
temp1:=strtofloat(edit1.text);
edit1.Clear ;
begin
if key=true
then
edit1.Text:=edit1.Text+'7'
else begin
edit1.Clear;
key:=true;
edit1.Text:='7';
end; end;
temp2:=temp1/temp3;
end;
end;
edit1.text:=floattostr(temp2);
key:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
key:=true;
end;
end.
begin
edit1.clear;
end;
procedure TForm1.Button13Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=1;
temp1:=strtofloat(edit1.text);
then
edit1.Text:=edit1.Text+'0'
else begin
edit1.Clear;
key:=true;
edit1.Text:='0';
end; end;
procedure TForm1.Button12Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'4'
else begin
edit1.Clear;
key:=true;
edit1.Text:='4';
end; end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'5'
else begin
edit1.Clear;
key:=true;
edit1.Text:='5';
end; end;
procedure TForm1.Button6Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'2'
else
begin
edit1.Clear;
key:=true;
edit1.Text:='2';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
Button15: TButton;
Button16: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'6'
else begin
edit1.Clear;
key:=true;
edit1.Text:='6';
end; end;
procedure TForm1.Button7Click(Sender: TObject);
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
end;
procedure TForm1.Button16Click(Sender: TObject);
//var n:integer;
// temp1:string;
begin
n:=4;
temp1:=strtofloat(edit1.text);
edit1.Clear;
end;
else begin
edit1.Clear;
key:=true;
edit1.Text:='9';
end; end;
procedure TForm1.Button10Click(Sender: TObject);
begin
if key=true
then
edit1.Text:=edit1.Text+'1'
else
begin
edit1.Clear;
key:=true;
edit1.Text:='1';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;