delphi 制作计算器除法出错
请问为什么这个除法的被除数在运行的时候出错unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classe...
请问为什么这个除法的被除数在运行的时候出错unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a:Integer;
b:Integer;
d:string;
c:string;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=edit1.Text +'1';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text:=edit1.Text +'2';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
c:='+';
a:=strtoint(edit1.Text);
edit1.Text:='';
b:=0;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
c:='/';
a:=StrToint(edit1.Text);
edit1.Text:='';
b:=0;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if b=0 then
b:=StrToint(edit1.Text);
if c='+'
then edit1.Text:=intToStr(a+b);
a:=StrToint(edit1.Text) ;
exit;
if c='/'
then
if b=0 then edit1.Text:='cuowu' else
if
b<>0
then edit1.Text:=FloatToStr(b / a);
a:=StrToint(edit1.Text) ;
end;
end 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a:Integer;
b:Integer;
d:string;
c:string;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=edit1.Text +'1';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text:=edit1.Text +'2';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
c:='+';
a:=strtoint(edit1.Text);
edit1.Text:='';
b:=0;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
c:='/';
a:=StrToint(edit1.Text);
edit1.Text:='';
b:=0;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if b=0 then
b:=StrToint(edit1.Text);
if c='+'
then edit1.Text:=intToStr(a+b);
a:=StrToint(edit1.Text) ;
exit;
if c='/'
then
if b=0 then edit1.Text:='cuowu' else
if
b<>0
then edit1.Text:=FloatToStr(b / a);
a:=StrToint(edit1.Text) ;
end;
end 展开
若以下回答无法解决问题,邀请你更新回答
展开全部
procedure TForm1.Button4Click(Sender: TObject);
begin
if b=0 then
b:=StrToint(edit1.Text);
if c='+'
then begin//猜亏猜这里加begin
edit1.Text:=intToStr(a+b);
a:=StrToint(edit1.Text) ;
exit;
end;//这里加个end,穗型if 语句后没有begin 和end,只能后面第一句起作用。所以上面会对a进行赋值,下面除法因为对a赋值改变,当然不会有正确的结果。
if c='/'
then
if b=0 then edit1.Text:='cuowu'空樱 else
if
b<>0
then edit1.Text:=FloatToStr(b / a);
a:=StrToint(edit1.Text) ;//结果有可能不为整数,这里会出错
end;
begin
if b=0 then
b:=StrToint(edit1.Text);
if c='+'
then begin//猜亏猜这里加begin
edit1.Text:=intToStr(a+b);
a:=StrToint(edit1.Text) ;
exit;
end;//这里加个end,穗型if 语句后没有begin 和end,只能后面第一句起作用。所以上面会对a进行赋值,下面除法因为对a赋值改变,当然不会有正确的结果。
if c='/'
then
if b=0 then edit1.Text:='cuowu'空樱 else
if
b<>0
then edit1.Text:=FloatToStr(b / a);
a:=StrToint(edit1.Text) ;//结果有可能不为整数,这里会出错
end;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询