谁有用delphi写的计算器?

Tianwl 2004-08-27 02:46:18
谁有用delphi写的计算器?功能:不需要任何+,-,*,/,sin,cos..按钮.直接在文本框内输入计算式,按下calculate就得到结果了,
...全文
219 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
getter 2004-08-28
  • 打赏
  • 举报
回复
我有一個,用後綴式求值的,可以計算+,-,*,/,^表達式
dejoy 2004-08-28
  • 打赏
  • 举报
回复
没有必要自己写,用上面控件包中的吧
dejoy 2004-08-28
  • 打赏
  • 举报
回复
很多,可以参看grideh、tms、rxlib、jvcl等控件包中计算器控件的代码。
yangsdfz 2004-08-28
  • 打赏
  • 举报
回复
................
这个做了干什么,晕
计算器还不如买一个好点的,送给你老板算了,呵呵,开玩笑的。
Tianwl 2004-08-28
  • 打赏
  • 举报
回复
不需要任何+,-,*,/,sin,cos..按钮.直接在文本框内输入计算式,按下calculate就得到结果了.急呀!!!明天就要缴活。
sunnycool 2004-08-27
  • 打赏
  • 举报
回复
对不起,没看清题目,把它删掉吧,不好意思
sunnycool 2004-08-27
  • 打赏
  • 举报
回复
刚学delphi时写的,随便看看吧。

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Label1: 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;
Button19: TButton;
Button20: TButton;
Button18: TButton;
XPMenu1: TXPMenu;
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 Button17Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button20Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
d:boolean;//判断按钮“点”是否被按下了
l:boolean;//判断按钮“零”是否被按下了
a1,a2,a3:real;//a1,第一个数;a2,第二个数;a3,结果;
jia,jian,cheng,chu:boolean;//判断加,减,乘,除按钮是否被按下了;
denghao:boolean;//判断等号是否被按下了;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'1';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'2';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'3';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'4';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'5';
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'6';
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'7';
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'8';
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
label1.Caption:=label1.Caption+'9';
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
label1.Caption:='';
d:=false;
l:=false;
denghao:=false;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
if l=false then
begin
label1.Caption:=label1.Caption+'0';
l:=true;
end
else
begin
if (d=true)or(strtofloat(label1.Caption)<>0) then label1.Caption:=label1.caption+'0';
end;
if denghao=true then
begin
label1.Caption:='';
denghao:=false;
end;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
if (d=false)and(label1.caption<>'') then
begin
label1.Caption:=label1.Caption+'.';
d:=true;
end;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
d:=false;
l:=false;
a1:=strtofloat(label1.Caption);
jia:=true;
label1.Caption:='';
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
d:=false;
l:=false;
a1:=strtofloat(label1.Caption);
jian:=true;
label1.Caption:='';
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
d:=false;
l:=false;
a1:=strtofloat(label1.Caption);
cheng:=true;
label1.Caption:='';
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
d:=false;
l:=false;
a1:=strtofloat(label1.Caption);
chu:=true;
label1.Caption:='';
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
d:=false;
l:=false;
a2:=strtofloat(label1.Caption);
if jia=true then begin a3:=a1+a2; jia:=false; end;
if jian=true then begin a3:=a1-a2; jian:=false; end;
if cheng=true then begin a3:=a1*a2; cheng:=false; end;
if (chu=true)and(a2<>0) then
begin a3:=a1/a2; chu:=false; end
else
begin
if a2=0 then showmessage('除数不能为零!');
end;
label1.Caption:=floattostr(a3);
denghao:=true;
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
close;
end;

end.
luckyboyforever 2004-08-27
  • 打赏
  • 举报
回复
还要判断优先级,括号.....

想起了数据结构.............
asd123789 2004-08-27
  • 打赏
  • 举报
回复
好象有点复杂
Tianwl 2004-08-27
  • 打赏
  • 举报
回复
fireflyer(雪阳):我没收到呀。我的邮箱:tian751029@sohu.com
wilowind 2004-08-27
  • 打赏
  • 举报
回复
难道想看源代码, 解析表达式只在学校学过
yangsdfz 2004-08-27
  • 打赏
  • 举报
回复
<dephi程序设计教程> 里面有
wintergoes 2004-08-27
  • 打赏
  • 举报
回复
没有!呵呵...
UP
fireflyer 2004-08-27
  • 打赏
  • 举报
回复
我有!!!
j790224@163.com

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧