delphi中edit1,edit2,edit3,edit4,edit5,通过随机函数覆值后,怎么让五个edit中内容都不一样呢?请写出代码,多谢

解决方案 »

  1.   

    while true do
    begin
    if (edit1.text=edit2.text) and () and() ....... then
    随机函数();
    else break;end;
      

  2.   

    取5个不同随机函数(可以放进数组),然后再给EDIT赋值
      

  3.   

    var
    a,b,c,d,e :string;
    begin
    Randomize;
    edit1.Text:=IntToStr(random(21)+1);
    edit2.Text:=inttostr(random(21)+1);
    edit3.Text:=inttostr(random(21)+1);
    edit4.Text:=inttostr(random(21)+1);
    edit5.Text:=inttostr(random(21)+1);
    a:=trim(edit1.Text);
    b:=trim(edit2.Text);
    c:=trim(edit3.Text);
    d:=trim(edit4.Text);
    e:=trim(edit5.Text);
    while true do
    if (a>b) or (a>c) or (a>d) or (a>e) or (b<a) or (b>c) or (b>d) or (b>e) or (c<a) or (c<b) or (c>d) or (c>e) or (d<a) or (d<b) or (d<c) or (d>e) or (e<a) or (e<b) or (e<c) or (e<d) then
    edit1.Text:=inttostr(random(21)+1);
    edit2.Text:=inttostr(random(21)+1);
    edit3.Text:=inttostr(random(21)+1);
    edit4.Text:=inttostr(random(21)+1);
    edit5.Text:=inttostr(random(21)+1);
      else break;//走到这一步就出现错误了,是怎么回事啊???????请高手指点!!!!
    end;
      

  4.   

    if ... then
    begin 
      edit1.Text:=inttostr(random(21)+1); 
      edit2.Text:=inttostr(random(21)+1); 
      edit3.Text:=inttostr(random(21)+1); 
      edit4.Text:=inttostr(random(21)+1); 
      edit5.Text:=inttostr(random(21)+1);
    end
    else begin
      ...
    end; 
      

  5.   

        else   break;//走到这一步就出现错误了,是怎么回事啊???????请高手指点!!!! 前边少个end
      

  6.   

    参考如下代码
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I, J: Integer;
      vEdit: TEdit;
    begin
      Randomize();
      with TList.Create do try
        for I := 1 to 21 do Add(Pointer(I)); // 得到全部1-21
        for I := 1 to 5 do
        begin
          TComponent(vEdit) := FindComponent(Format('Edit%d', [I]));
          if Assigned(vEdit) then
          begin
            J := Random(Count); // 随机抽取一个元素
            vEdit.Text := Format('%d', [Integer(Items[J])]);
            Delete(J); // 删除抽取的元素
          end;
        end;
      finally
        Free;
      end;
    end;