Delphi编辑简单计算器

2017-11-14 19:10:49来源:CSDN作者:qq_32869085人点击

分享
unit Unit1;interfaceuses  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 btn1Click(Sender: TObject);    procedure btn3Click(Sender: TObject);    procedure btn5Click(Sender: TObject);    procedure btn6Click(Sender: TObject);    procedure btn7Click(Sender: TObject);    procedure btn9Click(Sender: TObject);    procedure btn10Click(Sender: TObject);    procedure btn11Click(Sender: TObject);    procedure btn13Click(Sender: TObject);    procedure btn4Click(Sender: TObject);    procedure btn8Click(Sender: TObject);    procedure btn12Click(Sender: TObject);    procedure btn16Click(Sender: TObject);    procedure btn15Click(Sender: TObject);    procedure btn17Click(Sender: TObject);    procedure btn14Click(Sender: TObject);    procedure btn2Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  Form1: TForm1;  sum:Extended;  flag:Integer;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);beginedt1.Text:=edt1.Text+'1';end;procedure TForm1.btn2Click(Sender: TObject);beginedt1.Text:=edt1.Text+'2';end;procedure TForm1.btn3Click(Sender: TObject);beginedt1.Text:=edt1.Text+'3';end;procedure TForm1.btn5Click(Sender: TObject);beginedt1.Text:=edt1.Text+'4';end;procedure TForm1.btn6Click(Sender: TObject);beginedt1.Text:=edt1.Text+'5';end;procedure TForm1.btn7Click(Sender: TObject);beginedt1.Text:=edt1.Text+'6';end;procedure TForm1.btn9Click(Sender: TObject);beginedt1.Text:=edt1.Text+'7';end;procedure TForm1.btn10Click(Sender: TObject);beginedt1.Text:=edt1.Text+'8';end;procedure TForm1.btn11Click(Sender: TObject);beginedt1.Text:=edt1.Text+'9';end;procedure TForm1.btn13Click(Sender: TObject);beginedt1.Text:=edt1.Text+'.';end;procedure TForm1.btn4Click(Sender: TObject);beginsum:=StrToFloat(edt1.Text);edt1.Text:='';flag:=1;end;procedure TForm1.btn8Click(Sender: TObject);beginsum:=StrToFloat(edt1.Text);edt1.Text:='';flag:=2;end;procedure TForm1.btn12Click(Sender: TObject);beginsum:=StrToFloat(edt1.Text);edt1.Text:='';flag:=3;end;procedure TForm1.btn16Click(Sender: TObject);beginsum:=StrToFloat(edt1.Text);edt1.Text:='';flag:=4;end;procedure TForm1.btn15Click(Sender: TObject);begincase flag of1:edt1.Text:=FloatToStr(sum+StrToFloat(edt1.Text));2:edt1.Text:=FloatToStr(sum-StrToFloat(edt1.Text));3:edt1.Text:=FloatToStr(sum*StrToFloat(edt1.Text));4:if edt1.Text='0' thenShowMessage('除数不能为0')elseedt1.Text:=FloatToStr(sum/strtofloat(edt1.Text));end;end;procedure TForm1.btn17Click(Sender: TObject);beginedt1.Text:='';end;procedure TForm1.btn14Click(Sender: TObject);beginedt1.Text:=edt1.Text+'0';end;end.

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台