用delphi7如何写一个计算器啊

我是个DELPHI7的初学者啊

求助好心的高手告诉我啊

谢谢了啊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
delphi做的计算器。unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Scr: TLabel; 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; procedure Button1Click(Sender: TObject); procedure Button12Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button20Click(Sender: TObject); procedure Button19Click(Sender: TObject); procedure Button18Click(Sender: TObject); private { Private declarations } pnt,er,fb:boolean; fstnm:Extended; fbcaption:string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var temp:string; begin if er then exit; if pnt then scr.Caption:=scr.Caption+(sender as Tbutton).Caption else if (scr.Caption='0.') or fb then begin scr.Caption:=(sender as Tbutton).caption+'.'; fb:=false; end else begin temp:=scr.Caption; insert((sender as Tbutton).Caption,temp,length(temp)); scr.Caption:=temp; end; end; procedure TForm1.Button12Click(Sender: TObject); var temp:string; begin if er then exit; if scr.Caption<>'0.' then if pos('-',scr.Caption)>0 then begin temp:=scr.Caption; delete(temp,1,1); scr.Caption:=temp; end else scr.Caption:='-'+scr.Caption; end; procedure TForm1.FormCreate(Sender: TObject); begin pnt:=false; fstnm:=0; fb:=false; fbcaption:=''; er:=false; end; procedure TForm1.Button11Click(Sender: TObject); begin if er then exit; pnt:=true; end; procedure TForm1.Button13Click(Sender: TObject); begin if er then exit; if not fb then button20click(nil); if er then exit; fstnm:=strtofloat(scr.Caption); fbcaption:=(sender as Tbutton).Caption; fb:=true; pnt:=false; end; procedure TForm1.Button20Click(Sender: TObject); begin if er then exit; if fbcaption='+' then begin scr.Caption:=floattostr(strtofloat(scr.Caption)+fstnm); end; if fbcaption='-' then begin scr.Caption:=floattostr(fstnm-strtofloat(scr.Caption)); end; if fbcaption='*' then begin scr.Caption:=floattostr(strtofloat(scr.Caption)*fstnm); end; if fbcaption='/' then begin if scr.Caption<>'0.' then scr.Caption:=floattostr(fstnm/strtofloat(scr.Caption)) else begin scr.Caption:='zero divid error!'; er:=true; end; end; if pos('.',scr.caption)=0 then scr.Caption:=scr.Caption+'.'; fb:=true; pnt:=false; fbcaption:=''; end; procedure TForm1.Button19Click(Sender: TObject); begin pnt:=false; fstnm:=0; fb:=false; fbcaption:=''; er:=false; scr.Caption:='0.'; end; procedure TForm1.Button18Click(Sender: TObject); begin if er then exit; scr.Caption:='0.'; end; end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值