谁能告诉我在Delphi中实现在Case语句中写入字符串的方法?
例如:
    For i:=1 to UpperCase(Filename[i]) do
      begin
        Case FileName of
          'filename1':
              begin
                ...
              end;
          'filename2':
              begin
                ...
              end;
      end;什么办法都行,只要能解决问题就行!

解决方案 »

  1.   

    For i:=1 to UpperCase(Filename[i]) do
          begin
            Case i of
              1:
                  begin
                    ...
                  end;
              2:
                  begin
                    ...
                  end;
          end;
      

  2.   

    case 必须是有序的才可以。
    这是帮助里的原文
    where selectorExpression is any expression of an ordinal type (string types are invalid)
      

  3.   

    For i:=1 to UpperCase(Filename[i]) do
    这句能执行吗,UpperCase函数返回的是字串
      

  4.   

    for i := 1 to MaxLen do
    begin
      if AnsiCompareText(Filename[i],'filename1') == 0 then
         break;
    end;
    case i of
    1:begin ... end;
    2:begin ... end;
    ...
    end;
      

  5.   

    若字串已知,可以这样:
    定义…………
    Tmystr = (filename1, finlename2, ……);在case语句中
    var
      mystr: Tmystr;
    begin  
      …………
      case mystr of
        filename1: …………;
        filename2: …………;
      end;
      …………
    end;
      

  6.   

    用if也可以啊,干嘛总要case呢。
      

  7.   

    同意-》tglong(Dragon) 如果楼主想这样处理的话,必须这样定义,因为case语句的跳进类型必须是有序的类型,
      

  8.   

    WWWWA(aaaa) 又出现了:)呵呵。
      

  9.   

    tglong(Dragon)的方法有局限哦:)]
    其实解决方法就是避开它!WWWWA(aaaa) 的方法不错的!如果你非要判断字符的内容,那只有就IF了!
      

  10.   

    function GetIndex(s: String): Integer;
    var
      sl: TStrings;
    begin
      sl := TStringList.Create;
      sl.Text := 'STR1'#13#10 +
        'STR1'#13#10 +
        'STR1'#13#10 +
        ....
      Result := sl.IndexOf(s);
      sl.Free;
    end;.....  case GetIndex(UpperCase(Filename[i])) of 
        0: ...
        1: ...
        else
      end;
      

  11.   

    Case 语句中直支持
    字符和数字,不支持字符串。
      

  12.   

    case...
     1:
     2:...
     end;
    用数字 要不然用你要定义的
      

  13.   

    case 必须是有序的才可以。WWWWA(aaaa) 的对!
      

  14.   

    case 不能用字符串。要么用if,效果不会差很多
      

  15.   

            Case AnsiIndexText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']) of
              1: begin //Edit1.Text='a1'
                    ...
                 end;
              2:begin //Edit1.Text='a2'
                    ...
                 end;
              3:begin //Edit1.Text='a3'
                    ...
                 end;
              4:begin //Edit1.Text= 'a4'
                    ...
                 end;
          end;
      

  16.   

    大家新年好,元旦好~
    学习ing
      

  17.   

    For i:=1 to UpperCase(Filename[i]) do
          begin
            Case i of
              1:
                  begin
                    ...
                  end;
              2:
                  begin
                    ...
                  end;
          end;
      

  18.   

    case 必须是有序的才可以。
    如果有不規律字符串建議使用
    IF ..... THEN
       BEGIN
       ..
       END;
    IF ..... THEN
       BEGIN
       ..
    .......
       END;
      

  19.   

    谢谢 tglong(Dragon) !谢谢 mzzhf(大海)!