FORM上有EDIT1,EDIT2,EDIT3,EDIT4 BUTTON1 组件
我在BUTTON1的Click事件中判断 第一次输入 4个EDIT中的数字 与第二次输入的是否相同(可以打破顺序),怎么判断?
例 :第一次输入 EDIT1.TEXT =‘1’, EDIT2.TEXT =‘2’, EDIT3.TEXT =‘3’, EDIT4.TEXT =‘4’
第二次输入 EDIT1.TEXT =‘4’, EDIT2.TEXT =‘3’, EDIT3.TEXT =‘1’, EDIT4.TEXT =‘2’ 这样的输入的数字是相同的
谢谢

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    implementation{$R *.dfm}type
      PSortArray = ^TSortArray;
      TSortArray =  array[0..3] of Integer;
    var
      N1, N2 :  TSortArray ;procedure Sort(var A: array of Integer);
    var
      I, J, T: Integer;
    begin
      for I := High(A) downto Low(A) do
        for J := Low(A) to High(A) - 1 do
          if A[J] > A[J + 1] then
          begin
            //VisualSwap(A[J], A[J + 1], J, J + 1);
            T := A[J];
            A[J] := A[J + 1];
            A[J + 1] := T;
          end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var I : integer ;
    begin
       N1[0] := StrToInt(Edit1.Text );
       N1[1] := StrToInt(Edit2.Text );
       N1[2] := StrToInt(Edit3.Text );
       N1[3] := StrToInt(Edit4.Text );
       For I := 0 to ControlCount -1  do
        if (Components[I] is TEdit) then TEdit(Components[I]).Text := '' ;
      Button1.Enabled := False ;
      Button2.Enabled := True ;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var I,J : integer ;
    begin
       N2[0] := StrToInt(Edit1.Text );
       N2[1] := StrToInt(Edit2.Text );
       N2[2] := StrToInt(Edit3.Text );
       N2[3] := StrToInt(Edit4.Text );
          For I := 0 to ControlCount -1  do
             if (Components[I] is TEdit) then TEdit(Components[I]).Text := '' ;
       Sort(N1);
       Sort(N2);
       J := 0 ;
       for I := 0 to 3 do
         if N1[I] <> N2[I] then
          begin
            J := 1;
            break ;
          end ;
       if (J > 0)  then
       Application.MessageBox('不一样','提示',0)
       else
        Application.MessageBox('一样','提示',0) ;   Button1.Enabled := True ;
       Button2.Enabled := False ;
    end;end.