procedure TForm1.Button1Click(Sender: TObject);
begin
try
 if StrToInt(Edit1.Text) > StrToInt(Edit2.Text) then
 begin
   ShowMessage('Edit1的值不可大于Edit2的值');
   Edit2.Text:='';
   Edit2.SetFocus;
 end
 else
 begin
   ShowMessage('条件符合规则,可以继续运行');
 end;
except
  On e:Exception do
  begin
    ShowMessage('Edit1和Edit2只能输入纯数字');
    Edit2.Text:='';
    Edit2.SetFocus;
  end;
end;
end;

解决方案 »

  1.   

    就是一个简单的if else语句啊。
      

  2.   

    全部Unit:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        Button2: TButton;
        Label1: TLabel;
        Label2: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure FormShow(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        Function StrYesFloat(S:string):boolean;    // 检查字符串是Float字符  end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var S1,S2:string;
    begin
      S1:=Edit1.Text;
      S2:=Edit2.Text;
      if Not StrYesFloat(S1) then
      begin
        ShowMessage('"数据1"含有无效字符,请重新录入!');
        exit;
      end;
      if Not StrYesFloat(S2) then
      begin
        ShowMessage('"数据2"含有无效字符,请重新录入!');
        exit;
      end;
      if StrToFloat(S1)<StrToFloat(S2) then
      begin
        ShowMessage('"数据1"不能小于"数据2",请重新录入数据!');
        Exit;
      end;
     // 下一步操作代码....
      ShowMessage('OK!');
    end;procedure TForm1.FormShow(Sender: TObject);
    begin
      Edit1.text:='';
      Edit2.text:='';
    end;Function TForm1.StrYesFloat(S:string):boolean;    // 检查字符串是Float字符
    var I,J,K:integer;
        T:boolean;
    begin
      T:=True;
      result:=False;
      J:=0;
      K:=0;
      if Copy(S,1,1)='-' then S:=Copy(S,2,length(S)-1); // 首位字符- 负数有效
      for I:=1 to Length(S) do
      begin
        if not ((Ord(S[i])>=46) and (Ord(S[i])<=57) and (Ord(S[i])<>47)) then T:=False;
        if (Ord(S[i])>=48) and (Ord(S[i])<=57) then J:=J+1;
        if Ord(S[i])=46 then K:=K+1;
      end;
      if T then
        if J>0 then
          if K<2 then
            result:=True;
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      close;
    end;end.
      

  3.   

    SetFocus用在父窗口里可以,如果是在子窗口中,可能在点击了OK按钮后,子窗口就会关闭导致不能继续输入
      

  4.   

    在edit2的OnValidate事件中进行比较,问题已解决
      

  5.   

    无满意结帖,结帖人WinterFrog]