try except的用法

biossave 2002-04-09 09:41:00
procedure TForm1.BitBtn1Click(Sender: TObject);
var
str: string;
stnum: integer;
begin
str:='';
form2.adodataset1.active:=false;

str:='select * from ' +adotable1.tablename
+' where ' + combobox2.items[combobox2.itemindex]
+combobox3.items[combobox3.itemindex] +''''+edit1.text+'''';
showmessage(str);
try

form2.adodataset1.commandtext:=str;
form2.adodataset1.active:=true;
form2.show;

except

stnum:=strtoint(edit1.text);
str:='select * from ' +adotable1.tablename
+' where ' + combobox2.items[combobox2.itemindex]
+combobox3.items[combobox3.itemindex];
form2.adodataset1.commandtext:=str+stnum;
showmessage(form2.adodataset1.commandtext);
form2.adodataset1.active:=true;
form2.show;

try,except可以这样使用吗?
...全文
131 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
erickleung 2002-04-09
  • 打赏
  • 举报
回复
try....except

通常是用来捕捉系统错误. 如数据库不能连接, 或SQL数据库传回错误.
所以当真有错误发生时, 你未必得到你预期的程序.
例子

try
result := a/b;
except
result := 0; //当 b=0
end;
delphi_user 2002-04-09
  • 打赏
  • 举报
回复
呵呵。

try
except
end;
语法应该这样,我粗略看了程序,我觉得你需要在字符串转换的时候用到

try
stnum:=strtoint(edit1.text);
except
stnum:=0;
end;


5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧