| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:一个关于delphi程序代码的出错原因
只看楼主 加入收藏
cch8080
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-3-18
结帖率:100%
收藏
 问题点数:0 回复次数:2 
一个关于delphi程序代码的出错原因

各位高手们,你们好!我是一个新手,今天编了一个程序,程序的内容是这样的:unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: 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;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
var
s:word;
x,y:real;
v:boolean;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
s:=0;
x:=0;
y:=0;
v:=false;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if form1.Tag=1 then
begin
if tag=10 then panel2.Caption:='0.'
else panel2.Caption:=(sender as tspeedbutton).Caption;
form1.Tag:=0;
end
else panel2.Caption:=panel2.Caption+(sender as tspeedbutton).Caption;
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
form1.Tag:=1;
if v then
begin
x:=strtofloat(panel2.Caption);
v:=not v;
end
else
begin
y:=strtofloat(panel2.Caption);
case s of
0:panel2.Caption:=format('%g',[x+y]);
1:panel2.Caption:=format('%g',[x-y]);
2:panel2.Caption:=format('%g',[x*y]);
3:if y<>0 then
panel2.Caption:=format('%g',[x/y]);
else
begin
showmessage('不能以0为除数!');
panel2.Caption:=format('%g',[x]);
v:=false;
end;
4:begin
y:=0;
v:=false;
end;
end;
x:=strtofloat(panel2.Caption);
end;
s:=(sender as tspeedbutton).Tag;
end;
end.
但在我运行此程序时却出现了这样的出错提示:
[Error]Unit1.pas[90]:Undeclared identifier:'4'
[Fatal Error]Project1.dpr[5]:Could not compile used unit'Unit1.pas'
我找了好久都找不出原因,请各位高手帮帮忙,看下问题出在哪?
小弟在这先谢谢各位高手们!

搜索更多相关主题的帖子: delphi 代码 
2007-04-03 10:00
cypctt
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-4-2
收藏
得分:0 
3:if y<>0 then
panel2.Caption:=format('%g',[x/y]);
else

else前面的分号不要

任务交易、兼职的网站 http://www./index.php?r=360297
2007-04-03 10:31
anthony634
Rank: 6Rank: 6
来 自:西南交大
等 级:贵宾
威 望:24
帖 子:653
专家分:10
注 册:2006-6-8
收藏
得分:0 
3:if y<>0 then
panel2.Caption:=format('%g',[x/y]);//去掉分号,不然else是属于case的else
else
begin
showmessage('不能以0为除数!');
panel2.Caption:=format('%g',[x]);
2007-04-03 10:33
快速回复:一个关于delphi程序代码的出错原因
数据加载中...
 
   



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

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