新手求助delphi代码的错误,感激不尽
unit Unit1;interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,Math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
temp1:string; //第一个操作数
temp2:string; //第二个操作数
sky:boolean;
x2:char; //运算操作符
de:integer=0; //等号是否被按下
implementation
{$R *.dfm}
procedure Calc(x,y:double;op:char);
var
temresult:double;
Edit1: TEdit;
begin
case op of
'+':temresult:=x+y;
'-':temresult:=x-y;
'*':temresult:=x*y;
'/':temresult:=x/y;
'%':temresult:=Round(x) mod Round(y);
's':temresult:=sqrt(x);
'x':temresult:=1/x;
'^':temresult:=power(1,2);
end;
temp1:=floattostr(temresult);
temp2:='';
x2:=' ';
edit1.Text:=temp1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if sky =false then
begin
Edit1.Text := '';
sky := false;
temp1:=temp1+'1';
edit1.Text:=temp1;
end;
if (sky=true)and(temp1<>'')then
begin
temp2:=temp2+'1';
edit1.Text :=temp2;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
sky:=true;
if (temp1<>'') and (temp2<>'') then //先对上一次的运算求结果
begin
Calc(strtofloat(temp1),strtofloat(temp2),x2); //调用过程
end;
x2:='+';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if (temp1<>'') and (temp2<>'') and (x2<>'') then
begin
Calc(strtofloat(temp1),strtofloat(temp2),x2); //调用过程
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if sky=false then
begin
temp1:=temp1+'0';
edit1.Text:=temp1;
end;
if (sky=true) and (temp1<>'') and (temp2<>'0') then
begin
temp2:=temp2+'0';
edit1.Text :=edit1.Text+'0';
end;
if (sky=true) and (temp1<>'') and (temp2='0') and (de=0) then
begin
temp2:='0';
end;
if (sky=true) and (temp1<>'') and (temp2='') and (de=0) then
begin
temp2:='0';
edit1.Text :=edit1.Text +'0';
end;
if (sky=true) and (de=1) then
begin
temp1:=temp1+'0';
edit1.Text :=edit1.Text +'0';
end;
end;
end.
求助此段代码问题何在,按等号时出现access violation at address错误,已添加数据执行保护,错误依然存在,编译和运行时没有问题 请大神指教 先谢了。