跪求一个用delphi7做的计算器,能实现基本加减乘除基本功能。选修课作业,急用。。。谢谢
3个回答
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
Edit1: TEdit;
SpeedButton17: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Flag: Boolean = True; //。标记位
Flag1: Integer = 1; //计算方法标志位
num1, num2, result: Real;
flagresult: Boolean = False;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
str: string;
begin
str := Edit1.Text;
if (Length(str) = 1) and (str = '0') then
Edit1.Clear;
Edit1.Color := clBlue;
if ((Sender as TSpeedButton).Caption = '.') then
begin
if Flag then
begin
Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption;
Flag := False;
end
end
else
Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption;
end;
procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
Edit1.Color := clRed;
num2 := StrToFloatDef(Edit1.Text, 0.00);
case Flag1 of
1: result := num1 + num2;
2: result := num1 - num2;
3: result := num1 * num2;
4: if num2 = 0 then
begin
MessageBox(0, '除数为0', '', 0);
result := 0;
end
else
result := num1 / num2;
end;
Edit1.Text := FloatToStr(result);
end;
procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
Flag1 := (Sender as TSpeedButton).Tag;
num1 := StrToFloatDef(Edit1.Text, 0.00);
Edit1.Text := '0';
end;
procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
Flag := True; //。标记位
Flag1 := 1; //计算方法标志位
num1 := 0;
num2 := 0;
result := 0;
Edit1.Text := '0';
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
case key of
'1': SpeedButton1.Click;
'2': SpeedButton2.Click;
'3': SpeedButton3.Click;
'4': SpeedButton4.Click;
'5': SpeedButton5.Click;
'6': SpeedButton6.Click;
'7': SpeedButton7.Click;
'8': SpeedButton8.Click;
'9': SpeedButton9.Click;
'0': SpeedButton10.Click;
'.': SpeedButton11.Click;
'+': SpeedButton13.Click;
'-': SpeedButton14.Click;
'*': SpeedButton15.Click;
'/': SpeedButton16.Click;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
Edit1: TEdit;
SpeedButton17: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Flag: Boolean = True; //。标记位
Flag1: Integer = 1; //计算方法标志位
num1, num2, result: Real;
flagresult: Boolean = False;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
str: string;
begin
str := Edit1.Text;
if (Length(str) = 1) and (str = '0') then
Edit1.Clear;
Edit1.Color := clBlue;
if ((Sender as TSpeedButton).Caption = '.') then
begin
if Flag then
begin
Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption;
Flag := False;
end
end
else
Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption;
end;
procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
Edit1.Color := clRed;
num2 := StrToFloatDef(Edit1.Text, 0.00);
case Flag1 of
1: result := num1 + num2;
2: result := num1 - num2;
3: result := num1 * num2;
4: if num2 = 0 then
begin
MessageBox(0, '除数为0', '', 0);
result := 0;
end
else
result := num1 / num2;
end;
Edit1.Text := FloatToStr(result);
end;
procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
Flag1 := (Sender as TSpeedButton).Tag;
num1 := StrToFloatDef(Edit1.Text, 0.00);
Edit1.Text := '0';
end;
procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
Flag := True; //。标记位
Flag1 := 1; //计算方法标志位
num1 := 0;
num2 := 0;
result := 0;
Edit1.Text := '0';
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
case key of
'1': SpeedButton1.Click;
'2': SpeedButton2.Click;
'3': SpeedButton3.Click;
'4': SpeedButton4.Click;
'5': SpeedButton5.Click;
'6': SpeedButton6.Click;
'7': SpeedButton7.Click;
'8': SpeedButton8.Click;
'9': SpeedButton9.Click;
'0': SpeedButton10.Click;
'.': SpeedButton11.Click;
'+': SpeedButton13.Click;
'-': SpeedButton14.Click;
'*': SpeedButton15.Click;
'/': SpeedButton16.Click;
end;
end;
end.
追问
很感谢有代码,但表示建筑学的看不懂,根本不会用这软件,有没有可以直接运行的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已发 而且是比较专业的科学计算器
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单的,自己做吧,会写代码的人是没有这闲功夫做这没有用处的玩意儿的.除非你给点钱.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询