var
  s:shortint;
 t:boolean;case s of
1:begin
    ....
  end;
2:begin
    ....
  end;
3:begin
    if t then
      调用1
    else
      调用2
  end;如何写这样的代码;;;能调用吗///常量3调用1或2...如何调用呢..帮帮忙啊,高手..

解决方案 »

  1.   

    直接GOTO最简单了,效率也最高。case s of
    1:begin
    lab1:  ....
    end;
    2:begin
    lab2:  ....
    end;
    3:begin
      if t then
        goto lab1
      else goto lab2;
    end;
      

  2.   

    var
      s:shortint;
     t:boolean;case s of
    3:begin  end;//你如果没有写BREAK,程序会一直往下进行,自然也就运行了1和2的内容
            1:begin
        ....
      end;
    2:begin
        ....
      end;
      

  3.   

    to: SNYQ411(洋溢)这位兄台想必是混淆了 Delphi 与 C 的概念吧?
    在 Delphi 的 Case 语句中是不需要写那个 Break 的!
      

  4.   

    你先把1,2要实现的过程定义成一个函数
    function proc1( )...          
      begin
     ...                          
      end;function proc1( )....  
    begin
    ...
    end;.....case s of
    1:proc1;
    2:proc2;
    3:begin
        if t then
          proc1
        else
          proc2
      end;在比较复杂一点的程序里建议少用goto语句,因为降低了程序的可读.容易造成混乱.简单程序里用还是很简练.
      

  5.   

    改成着样吧.
    var
      s:shortint;
     t:boolean;
    if s=3 then
     if t then s:=1 else s:=2
    case s of
    1:begin
        ....
      end;
    2:begin
        ....
      end;