在delphi7中选择结构为if then else但只能把条件分为两个条件,有没有选择结构可以把条件分为多个条件,
如 if a<=10 then
     begin
     end
   else
     begin
       if a>10 then
       ....  
       else
       .... 
     end
有没有类似sql中case when ...then... 
                    when ...then...
                    when ...then...
                    when ...then...
                    when ...then...
                    else
                    .....
                end;  
               
                    

解决方案 »

  1.   

    var
     s : integer;
    case s of
        1 : Color := clRed;
        2 : Color := clYellow;
        3 : Color := clBlue;
      end;
      

  2.   


    例子一:case I of  1..5: Caption := 'Low';
      6..9: Caption := 'High';
      0, 10..99: Caption := 'Out of range';
    else
      Caption := '';
    end;这相当于下面:if I in [1..5] then  Caption := 'Low'
      else if I in [6..10] then
        Caption := 'High'
        else if (I = 0) or (I in [10..99]) then
          Caption := 'Out of range'
          else
            Caption := '';另外的例子case MyColor of  Red: X := 1;
      Green: X := 2;
      Blue: X := 3;
      Yellow, Orange, Black: X := 0;
    end;case Selection of  Done: Form1.Close;
      Compute: CalculateTotal(UnitCost, Quantity);
    else
      Beep;
    end;
      

  3.   

    case语法即使是if也是可以的if a > 10 then
    beginend
    else if a > 9 then
    beginend
    else if a > 8 then
    beginend
    ... 
      

  4.   

    不可以但你可以把定义为常量
    const
      clRed = 1;
      clYellow = 2;
      clBlue = 3;
      

  5.   

      不行。必须是ordinal type.
                 string is invalid.
      

  6.   

    可以把1、2、3换成字符型的数据吗?不好意思,刚才说错了,我以为你说字符串
    字符型是可以的
    case s of 中的S必须为ordinal  type,而string types是不行的
    字符型如下:var s:char;
    begin
      s:='3';
      case s of
        '1':showmessage(s);
        '2':showmessage(s);
      else
         showmessage(s);
      end;
    end;
      

  7.   

    使用if ... then ... else ... end
    也可以使用case ... of语句进行多条件判断,
    当然,所判断的数据类型需要根据实际的类型进行赋值!
      

  8.   

    1、2、3不能是字符串吗?
    下面的代码用case 怎样写?
    if dw='包装一' then...
    else 
      begin
       if dw='包装二' then ...
       else 
       ...
      end;
      

  9.   

      字符串的是不可以的。
      在delphi帮助文档中你可以找到一段话
      case selectorExpression of
      caseList1: statement1;
      ...
      caseListn: statementn;
      endwhere selectorExpression is any expression of an ordinal type (string types are invalid)
      可见string类型是不可以的
      
       
      

  10.   

      不信你可以试试,肯定提示ordinal type required.
      就用if else不就可以了吗?能达到目的即可。
      

  11.   

    http://apps.hi.baidu.com/share/detail/5482166
    这是方法
      

  12.   

    凡事有变通嘛。//var strList: TStringList;strList := TStringList.Create;
    strList.Add('Beijing');
    strList.Add('Tianjing');
    strList.Add('Shanghai');
    strList.Add('Chongqing');
    str := 'Chongqing';
    case strList.IndexOf(str) of
    0: ShowMessage('First');
    1: ShowMessage('Second');
    2: ShowMessage('Third');
    3: ShowMessage('Forth');
    else ShowMessage('Other');
    end;
    strList.Free;
      

  13.   

    case X of 
    1:
    2:
    .
    .
    .
    end;
    注意,X只接受整形,列举,还有一个忘记了,不接受字符串
      

  14.   

      在c/c++中的switch case里面的case,也只支持int 和char,同样它们也不支持string,
      难道你要说这也是c/c++的bug吗?
      而且delphi本身也没说自己的case of就支持string类型,如果它自称可以支持string类型但没有实现,那就叫bug。
      查了一下资料,c#支持int,char和string,但是这也只能说c#在这点上有所改进,却不能说c,c++,delphi在条件语句中有不支持string的bug.
      
      
     
      
      

  15.   

    也不能说是bug,只是不支持。
    使用 if... then else if... then 也同样可以的。
      

  16.   

    可使用case of 或if ... then else if ...嵌套式語句即可