| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 664 人关注过本帖
标题:新手求助delphi代码的错误,感激不尽
只看楼主 加入收藏
loveljq
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-4-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
新手求助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错误,已添加数据执行保护,错误依然存在,编译和运行时没有问题 请大神指教  先谢了
搜索更多相关主题的帖子: delphi procedure 
2013-04-12 19:22
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
以下是引用loveljq在2013-4-12 19:22:16的发言:

 
 
 
编译和运行时没有问题 请大神指教  先谢了


既然运行没问题  那你问啥呢

DO IT YOURSELF !
2013-04-14 22:41
有容就大
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:10 
设置断点调试下 不然目测怎么找到啊?

梅尚程荀
马谭杨奚







                                                       
2013-04-16 12:03
快速回复:新手求助delphi代码的错误,感激不尽
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033651 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved