请问这样可以吗?(100分)

  • 主题发起人 主题发起人 kevenzhang
  • 开始时间 开始时间
K

kevenzhang

Unregistered / Unconfirmed
GUEST, unregistred user!
在用CASE ..OF..时如果 其中变量我无法知道
在什么域中,但我知道会有一个值存在,但我用时
却出错 比如:


VAR
T:STRING;
BEGIN
T:=TIMETOSTR(NOW);
CASE T OF
'17:40':....
END;

这样表达是不是不行,哪应怎样表达合适
 
不行,看看case的帮助

The case statement provides a readable alternative to complex nested if conditionals. A case statement has the form

case selectorExpression of

caseList1: statement1;
...
caseListn: statementn;
end

[red]where selectorExpression is any expression of an ordinal type (string types are invalid) [/red]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.
 
字符查照函數就可以了
 
string types are invalid)

就这一句查下字典就行了
 
VAR
T:STRING;
BEGIN
T:=TIMETOSTR(NOW);
if T='17:40' then :....
END;

case 的变量只能是 cardinal
 
CASE变量只能是有序变量
例如
数字,枚举量等
 
同意jsxjd,case变量只能是数字!还有TimeToStr函数得到的结果几乎不可能用"="判断
选中,用DateToStr还差不多!
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1406114
 
case的变量是[red]ordinal type[/red]
即[red]序数类型[/red]
并不局限于数字
 
后退
顶部