问答1 问答5 问答50 问答500 问答1000
网友互助专业问答平台

用delphi做一个简单计算器2

提问网友 发布时间:2023-10-28 07:34
声明:本网页内容为用户发布,旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:1656858193@qq.com
1个回答
热心网友 回答时间:2024-05-16 19:05
试试这个

unit Unit1;

interface

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

type
TForm1 = class(TForm)
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;
Button17: TButton;
procere Button4Click(Sender: TObject);
procere Button1Click(Sender: TObject);
procere Button2Click(Sender: TObject);
procere Button3Click(Sender: TObject);
procere Button5Click(Sender: TObject);
procere Button6Click(Sender: TObject);
procere Button7Click(Sender: TObject);
procere Button9Click(Sender: TObject);
procere Button10Click(Sender: TObject);
procere Button11Click(Sender: TObject);
procere Button13Click(Sender: TObject);
procere Button8Click(Sender: TObject);
procere Button12Click(Sender: TObject);
procere Button15Click(Sender: TObject);
procere Button16Click(Sender: TObject);
procere Button17Click(Sender: TObject);
procere Button14Click(Sender: TObject);
procere FormCreate(Sender: TObject);
private
procere SetEditText(info: string);
{ Private declarations }
public
{ Public declarations }
end;
type //自定义一个Tcompute的类

Tcompute = object
private //保护类中成员数据的安全

temp1: double;
temp2: double;
temp3: double;
sign: Char;

public //把类中的成员函数进行共享

function Add(x: double; y: double): Double;
function Sub(x: double; y: double): Double;
function Mult(x: double; y: double): Double;
function Dived(x: double; y: double): Double;

end;
var
Form1: TForm1;
Info: Tcompute; //声明Info是类Tcompute的对象
oldinfo:string;

implementation

function Tcompute.Add(x: double; y: double): Double; //进行类的定义与实现

begin
Result := x + y;
end;

function Tcompute.Sub(x: double; y: double): Double;
begin
Result := x - y;
end;

function Tcompute.Mult(x: double; y: double): Double;
begin
Result := x * y;
end;

function Tcompute.Dived(x: double; y: double): Double;
begin
if (y = 0) then begin
Form1.Edit1.text:='1111111111';
//ShowMessage('除数不能为0!'); //这里判断除数不能为0
Result := x;
end else
Result := x / y;
end;

{$R *.dfm}

procere TForm1.Button4Click(Sender: TObject);
begin
oldinfo := '';
SetEditText('');
Info.sign := ' ';
Info.temp1 := 0;
Info.temp2 := 0;
end;

procere TForm1.Button1Click(Sender: TObject);
begin
SetEditText('7');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button2Click(Sender: TObject);
begin
SetEditText('8');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button3Click(Sender: TObject);
begin
SetEditText('9');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button5Click(Sender: TObject);
begin
SetEditText('4');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button6Click(Sender: TObject);
begin
SetEditText('5');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button7Click(Sender: TObject);
begin
SetEditText('6');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button9Click(Sender: TObject);
begin
SetEditText('1');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button10Click(Sender: TObject);
begin
SetEditText('2');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button11Click(Sender: TObject);
begin
SetEditText('3');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button13Click(Sender: TObject);
begin
SetEditText('0');
Info.temp1 := StrTofloat(Edit1.text);
end;

procere TForm1.Button8Click(Sender: TObject);
begin
Button17Click(nil);
Info.temp2 := Info.temp1;
Info.sign := '+';
oldinfo := '';
end;

procere TForm1.Button12Click(Sender: TObject);
begin
Button17Click(nil);
Info.temp2 := Info.temp1;
Info.sign := '-';
oldinfo := '';
end;

procere TForm1.Button15Click(Sender: TObject);
begin
Button17Click(nil);
Info.temp2 := Info.temp1;
Info.sign := '*';
oldinfo := '';
end;

procere TForm1.Button16Click(Sender: TObject);
begin
Button17Click(nil);
Info.temp2 := Info.temp1;
Info.sign := '/';
oldinfo := '';
end;

procere TForm1.Button17Click(Sender: TObject);
begin
if Info.sign<>' ' then oldinfo := '';
if (Info.sign = '+') then
SetEditText(FloatToStr(Info.Add(Info.temp2, Info.temp1)))
else if (Info.sign = '-') then
SetEditText(FloatToStr(Info.Sub(Info.temp2, Info.temp1)))
else if (Info.sign = '*') then
SetEditText(FloatToStr(Info.Mult(Info.temp2, Info.temp1)))
else if (Info.sign = '/') then
SetEditText(FloatToStr(Info.Dived(Info.temp2, Info.temp1)));
if Edit1.Text<>'' then
Info.temp1 := StrToFloat(Edit1.Text);
Info.sign := ' ';
end;

procere TForm1.Button14Click(Sender: TObject);
begin
SetEditText('.');
Info.temp1 := StrToFloat(Edit1.Text);
end;

procere TForm1.SetEditText(info:string);
begin
Edit1.Text := oldinfo + info;
oldinfo := Edit1.Text;
end;

procere TForm1.FormCreate(Sender: TObject);
begin
oldinfo := '';
end;

end.追问看不懂哎,老师给我们的程序就是我发的,可我不明白为什么他会报错。。。

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

如何用C#做一个简单播放器1 谁有delphi制作的简单播放器 给发个 ,十分感谢!!! 帮忙用delphi软件制作一个简单的多媒体播放器3 冻对虾多少钱一斤50一60是什么意思26 如何追求狮子座女生?喜欢什么?48 狮子座怎么能吸引女孩 日常穿的话,阿迪达斯什么系列的鞋子穿的最舒服?298 硬脂酸锌对胶料的影响 数字媒体技术的就业方向是什么?395 什么跑鞋适合短跑,不是钉鞋的17 医院副院长可以到高校兼职工作吗 对方把微信删了,还能看到对方和朋友圈吗 如何鉴别水杨酸 阿司匹林 苯甲酸 用化学方法的哦 乳腺纤维瘤手术(1)术后对胸部外观或者大小会有影响吗?(2)会留下疤痕... 新概念英语第一册Lesson1——2—专辑:《新概念英语第一... 三国战记风云再起赵云连招第二个三分天下打不到! 50岁男人最近眼圈和眼角青了怎么办 怎样进入狮子座女生内心159 微信如何注销?5333 机组背压保护锅炉MFT吗 660W超超临界机组 有FCB模块... 数字媒体技术专业的就业方向有哪些?40 徐州安泰工程塑料有限公司怎么样? 手机号丢了上不去了怎么办? 用啊”和“哦”的声音,用手触摸喉咙部位,用语言描述你感受到的...3 一个手机号能注册两个吗? 一个号码如何注册两个 12岁男该,适合哪些运动?4 从安徽到上海多远?22 最后发的是中专证还是大专证 怎么改第二次已设置过怎么改 从安徽到上海最快要多少小时15 入住新房时的那些五谷怎处理76 入住新房五谷是哪些1 新房在墙壁里的四个角放五谷杂粮是什么意思30 为什么梦见龙与自己对话?4 竹席上的虫,是什么虫,怎么去除?10 zoom是什么意思,为什么我买的鞋上面会有zoom的标志?70 如何用DELPHI 7制作一个媒体播放器? 歇后语盲猫捉老鼠下一句是2 床上席子上这种会爬很小的虫子是什么虫子.有害吗? 太小了只能...25
Top