起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 142|回复: 8

【结贴】代码编译不了。case of 中应该是什么类型**

[复制链接]
发表于 2008-4-22 14:00:28 | 显示全部楼层 |阅读模式
case LX of
    'FS':
      Result := '1';
    'FF':
      Result := '2';
    'SF':
      Result := '3';
    'SS':
      Result := '4';
  else
    Result := '1';
  end;
[错误]Biz:\OPERATION\XMGL\XMGL\XMRWYWXX.INFO.DIR\XMRWSJWG.FormDoc.pas(404, 5): Incompatible types: "Ordinal" and "String"
回复

使用道具 举报

发表于 2008-4-22 14:50:32 | 显示全部楼层
LX是什么?数组么?贴出来看一下
回复 支持 反对

使用道具 举报

发表于 2008-4-22 15:01:53 | 显示全部楼层
一般语法应该为:   
  case   可选择表达式   of   
          常量:   语句1;   
            。               。;   
            。               。;   
            。               。;   
  else   
          语句   
  end;   
  表达式应为顺序数据类型。(整型/字符型/布尔型/子界型等都可以。)   
建议用整型是最合适的。   

更多帮助可以看delphi帮助或者网上找
回复 支持 反对

使用道具 举报

发表于 2008-4-22 15:03:16 | 显示全部楼层
可以看看delphi帮助。下面是我拷贝的
where selectorExpression is any expression of an ordinal type (string types are invalid) and each caseList is one of the following:

A numeral, declared constant, or other expression that the compiler can evaluate without executing your program. It must be of an ordinal type compatible with selectorExpression. Thus 7, True, 4 + 5 * 3, 'A', and Integer('A') can all be used as caseLists, but variables and most function calls cannot. (A few built-in functions like Hi and Lo can occur in a caseList. See Constant expressions.)
        A subrange having the form First..Last, where First and Last both satisfy the criterion above and First is less than or equal to Last.

A list having the form item1, ..., itemn, where each item satisfies one of the criteria above.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-4-22 16:00:02 | 显示全部楼层
我case  里是字符的。编译不过去。
LX :String;
case LX of
    'FS':
      Result := '1';
    'FF':
      Result := '2';
    'SF':
      Result := '3';
    'SS':
      Result := '4';
  else
    Result := '1';
  end;
这就是全部代码。
提示错误:Incompatible types: "Ordinal" and "String"
回复 支持 反对

使用道具 举报

发表于 2008-4-22 16:17:33 | 显示全部楼层
string char  类型可不同哦!!

where selectorExpression is any expression of an ordinal type (string types are invalid) and each caseList is one of the following:

string types are invalid
string types are invalid
string types are invalid
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-4-22 16:28:34 | 显示全部楼层
那里类型不同了。
回复 支持 反对

使用道具 举报

发表于 2008-4-22 16:43:07 | 显示全部楼层
字符串不行,整型、字符型、布尔型、子界型可以
回复 支持 反对

使用道具 举报

发表于 2008-5-15 10:36:15 | 显示全部楼层
由于长时间没有回复,先结贴了,有问题请开新帖。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-13 02:28 , Processed in 0.044387 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表