请哪位高手给个delphi 7编写的计算器代码,只要加减乘除简单动算就可以了,不胜感谢!

高分奖励,如若可行,追加高分!!ahhwb@126.com... 高分奖励,如若可行,追加高分!!ahhwb@126.com 展开
 我来答
BOBO的小可爱
2012-04-10
知道答主
回答量:8
采纳率:0%
帮助的人:3.7万
展开全部
昨天我做了一个简单的计算器。
其实原理很简单,就是一个表明“加减乘除符号”的变量fuhao,和一个string型的变量firststr(来存储第一个edt1.text里的数据)。当用户按下“加号”时,fuhao := 1;firststr:=edt1.text;edt1.clear;(把edt1.text里的数据清空!)然后用case fuhao of 判断用户输入的是什么运算符,然后做运算。其实很简单的。需要源代码的话你就按照下边的那个写:其实如果你是新手的话,还是写的简单一点好,复杂的话不利于你的“成就感”!嘿嘿,编程慢慢来!
记得选我为最佳答案奥亲!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;

type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
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;
BitBtn1: TBitBtn;
Image1: TImage;
procedure BitBtn1Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Label1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
temp1:string;
temp2:double;
n:integer;
implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
form1.Edit1.Clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Edit1.Text:=edit1.Text+'1';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'2';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'3';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'4';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'5';
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'6';
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'7';
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'8';
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'9';
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'0';
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
n:=1;
temp1:=edit1.Text;
edit1.clear;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
n:=2;
temp1:=edit1.Text;
edit1.clear;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
n:=3;
temp1:=edit1.Text;
edit1.clear;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
n:=4;
temp1:=edit1.Text;
edit1.clear;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
case n of
1:temp2:=strtofloat(temp1)+strtofloat(edit1.Text);
2:temp2:=strtofloat(temp1)-strtofloat(edit1.Text);
3:temp2:=strtofloat(temp1)*strtofloat(edit1.Text);
4:if strtofloat(edit1.Text)=0 then
begin
showmessage('除数不能为零!');
exit;
end
else
temp2:=strtofloat(temp1)/strtofloat(edit1.Text);
end;
edit1.Text:=floattostr(temp2);
end;

procedure TForm1.Image1Click(Sender: TObject);
begin
messagedlg('此处没有设置特定的功能!',mterror,[mbok],0);
end;

procedure TForm1.Label1DblClick(Sender: TObject);
begin
messagedlg('不能操作!',mtinformation,[mbok],0);
end;

end.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式