试一下用:
i:=Int(Random(10));

解决方案 »

  1.   

    我写
    i:=random(form4.hh);
    w:=trunc(i);
    case w of
        0: begin
          image1.picture:=image2.picture;
           end;
        1:begin
          image1.picture:=image3.picture;
           end;
    系统提示:constant expression expected
    但我用if w=0 then image1.picture:=image2.picture;
    if w=1 then image1.picture:=image3.picture;
    就可以编译通过,执行也没问题,请问这两有什么区别?
      

  2.   

    Random(10); //返回的就是整数 范围是0 .. 9
    Random(); //返回的是一个实数 范围是0 .. 1
      

  3.   

    谁说TRUNC是整形了?类型上,I是什么值他就是什么值了。
    CASE W OF 
         W(1):
         W(2):要求W 完全等于W(1)。
      

  4.   

    random(10) 返回的确实是整数,我试验了, 用Case语句可以啊,不知道你用的是什么版本?
    我的例子如下,感觉应该和你的一样。而运行结果也没有显示啊。我用的Delphi5.0.
    procedure TForm1.Button1Click(Sender: TObject);
    var data:integer;
    begin
        data:=random(10);
        case data of
        1:showmessage('1');
        2:showmessage('2');
        3:showmessage('3');
        else showmessage('others');
        end;
    end;