如何实现数据录入框在数据录入无效时给与提示?比如时间录入框录入 2003-2-30 时自动提示输入无效。[email protected]

解决方案 »

  1.   

    在edit的onkeypress里  if key = #13 then
       try
         strtodate(edit1.Text);
       except showmessage('asdf');
       end;
      

  2.   

    在发生输入事件时检查.例如
    procedure TForm1.Edit1Change(Sender: TObject);
    begin
      if 判断 then
       提示
    end;
      

  3.   

    在Edit的onExit里,一定要编译后直接运行程序才能看到。procedure TForm1.Edit1Exit(Sender: TObject);
    begin
      try
       StrToDate(Edit1.Text);
      except
       Application.MessageBox(PChar('时间格式为:2003-2-30'),'错误',MB_OK+MB_ICONINFORMATION);
       Edit1.SetFocus;
      end;
    end;