Case...of的用法出错

cybercobra 2000-07-14 12:25:00
各位大虾,小弟下面的一段程序出错,请各位帮忙看看是哪里出毛病了,是不是Case的用法不对,多谢!!!
其中ComboBox_Exe_Cond是一个ComboBox,包括'已完成'和'未完成'两个Items.
出错信息我注在对应的行后面了.从错误信息来看,好像是要求Case后面的变量要是一个序数类型,但是在help中并没有找到这样的说法.

if Trim(ComboBox_Exe_Cond.Text) <> '' then
Case Trim(ComboBox_Exe_Cond.Text) of {错误信息:Ordinal type required.}
'已完成':{错误信息:Incompatible Types:'Integer' and 'String'}
begin
if f_Empty<>4 then
ls:= ls + 'and Exe_cond=''1'''
else
ls:= ls + 'Exe_cond=''1'''
end;
'未完成':{错误信息:Incompatible Types:'Integer' and 'String'}
begin
if f_Empty<>4 then
ls:= ls + 'and Exe_cond=''0'''
else
ls:= ls + 'Exe_cond=''0'''
end;
else begin
raise Exception.Create('合同执行情况输入错误!');
ComboBox_Exe_Cond.SetFocus;
end
end
...全文
201 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kxy 2000-07-14
  • 打赏
  • 举报
回复
看看Case statements 的帮助
where selectorExpression is any expression of an ordinal type (string types are invalid)
Michaelyfj 2000-07-14
  • 打赏
  • 举报
回复
7030朋友的写法是正确的,你可以试一试!
7030 2000-07-14
  • 打赏
  • 举报
回复
把case...of 语句改成如下:
case combobox_exe_cond.itemindex of
0:begin
{state}
end;
1:begin
{state}
end;
end;
cybercobra 2000-07-14
  • 打赏
  • 举报
回复
多谢多谢多谢多谢多谢多谢多谢多谢!!!
Hibin 2000-07-14
  • 打赏
  • 举报
回复
为了程序的易读性,用枚举。
meijg 2000-07-14
  • 打赏
  • 举报
回复
7030是对的,case 只能处理序数类型的变量,字符串是肯定不行的

5,386

社区成员

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

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