|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
unit jisuanqiv2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, Mask;
type
TForm1 = class(TForm)
SpeedButton0: TSpeedButton;
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;
SpeedButton17: TSpeedButton;
Edit1: TEdit;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton0Click(Sender: TObject);
procedure SpeedButton10Click(Sender: TObject);
procedure SpeedButton11Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
procedure SpeedButton13Click(Sender: TObject);
procedure SpeedButton14Click(Sender: TObject);
procedure SpeedButton16Click(Sender: TObject);
procedure SpeedButton17Click(Sender: TObject);
procedure SpeedButton15Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
num1,num2,num3,temp:double;
subt,mult,divi:Integer;
Flag:Integer;
Flag1:Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.Handle,GWL_STYLE,GetWindowLong(Edit1.Handle,GWL_STYLE) Or ES_RIGHT);
num1:=0;
num2:=0;
num3:=0;
temp:=0;
subt:=0;
mult:=0;
divi:=0;
Edit1.Text:='';
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '1';
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '2';
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '3';
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '4';
end;
procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '5';
end;
procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '6';
end;
procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '7';
end;
procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '8';
end;
procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '9';
end;
procedure TForm1.SpeedButton0Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '0';
end;
procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
Edit1.Text:=Edit1.Text + '.';
end;
procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
num1:=StrToFloat(Edit1.Text);
Flag:=1;
Edit1.Text:='';
temp:=num1+temp;
end;
procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
If (subt>=1) then
begin
num1:=StrToFloat(Edit1.Text);
Flag:=2;
Edit1.Text:='';
temp:=temp-num1;
end
Else
begin
num1:=StrToFloat(Edit1.Text);
Flag:=2;
Edit1.Text:='';
temp:=num1;
end;
subt:=subt+1;
end;
procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
If (mult>=1) then
begin
num1:=StrToFloat(Edit1.Text);
Flag:=3;
Edit1.Text:='';
temp:=temp * num1;
end
Else
begin
num1:=StrToFloat(Edit1.Text);
temp:=num1;
Flag:=3;
Edit1.Text:=''
end;
mult:=mult + 1;
end;
procedure TForm1.SpeedButton14Click(Sender: TObject);
begin
If (divi>=1) then
begin
num1:=StrToFloat(Edit1.Text);
Flag:=4;
Edit1.Text:='';
temp:=temp / num1;
end
Else
begin
Flag:=4;
num1:=StrToFloat(Edit1.Text);
temp:=num1;
Edit1.Text:='';
end;
divi:=divi+1;
end;
procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
Edit1.Text:=Copy(Edit1.Text,1,Length(Edit1.text)-1);
end;
procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
num2:=StrToFloat(Edit1.Text);
case (Flag) of
1:num3:=temp + num2;
2:num3:=temp - num2;
3:num3:=temp * num2;
4:num3:=temp / num2;
end;
Edit1.text:=FloatToStr(num3);
num1:=0;
num2:=0;
num3:=0;
temp:=0;
subt:=0;
mult:=0;
divi:=0;
end;
procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
Form1.FormCreate(self);
Label1.Visible:=True;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
Label1.Visible:=False;
end;
end.
发这个自制的千疮百孔的计算器,为了响应一下小甲鱼老师号召,同时也在论坛冒个泡。。。
写个计算器,就这种最简单的,个人感觉还是挺费劲的,代码写的个人感觉也十分不精简,涉及到蛮多的算法,我好多都还不会,所以这个计算器还是存在很多问题:
1.输入两个以上小数点会报错
2.由于我不会筛选字母和数字以及符号,所以就把edit设置成只读了(还请各位鱼友不惜赐教应该如何筛选,感激不尽)
3.由于技术有限,才学不久,视频教程刚学到25讲。算法上出了一些问题,导致同种运算可以连续进行,不同种类运算交叉进行的时候会出现问题 : 比如:9-1-1=7 没问题 , 但是9-6+7就算不对了关于这个问题,还请各位鱼友指点一下怎么改善代码才能解决这个问题,在此先谢过了:handshake
下面附上代码
|
|