我是想进行字符串匹配啊,这几行代码如下这的编译通不过, 为什么     strName ='lib';     case   strName of
     case 'lib' : Result := 'lib';
     else
           Result := 'sss';
     end;

解决方案 »

  1.   


         strName ='lib';     case   strName of
         'lib' : Result := 'lib';
         else
               Result := 'sss';
         end;
      

  2.   

    case语句不能用字符串变量,只能用int或枚举
      

  3.   

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

  4.   

    case语句不支持string类型的选择,
    你可以把它转化为整型,如:
     if strName ='lib' then i:=0;
         .
         .
     case  i of
         0 : Result := 'lib';
         else
               Result := 'sss';
         end;
      

  5.   

    strName ='lib';     if strName = 'lib' then 
           Result := 'lib'
         else
           Result := 'sss';
      

  6.   

    老大!还转什么整型啊?这不多此一举么?
    if strName ='lib' then Result:='lib';     
    ...不就完了么?
     
      

  7.   

    case 语句中的条件必须是元数据类型,string 不是元数据类型,所以编译通不过。
      

  8.   

    The case statement may provide a readable alternative to deeply nested if conditionals. A case statement has the formcase selectorExpression of
    caseList1: statement1;
      ...
    caseListn: statementn;
    endwhere 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.看清楚了
    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)
      

  9.   

    delphi中 case只能判断 Integer 或 char
      

  10.   

    先把若干的情况放在TSTRINGLISTOBJECT里面
    然后用i:=TSTRINGLISTOBJECT.indexof(yourcasestring)
     然后  
     case  i of
         0 : Result := 'lib';
         else
               Result := 'sss';
         end;
      

  11.   

    用IF语句套吧.CASE语句中只能用序数类型.如INTEGER,BOOLEAN,枚举类型等.