窗体上应该还有个ok按钮吧,把上面的代码写在btnOKOnClick事件里好点

解决方案 »

  1.   

    可是你为什么非要用edit控件的OnExit事件来判断呢?把判断语句放到“确定”按钮的OnClick事件中检查不行吗?
    从用户使用角度,也许并不喜欢频繁的弹出对话框,放到最后统一的处理也许更好。
      

  2.   

    这样行不行,变态做法,因为你要点cancel的话,鼠标就要放到按钮上
    if length(trim(passwordedit.text))<6 and 鼠标当前位置不在button的区域里面 then
    begin
      MessageDlg('Password length must greate 6l!',mtInformation,[mbOk],0);
      passwordedit.SetFocus;
    end
      

  3.   

    在程序中,对edit进行onexit判断,如:
    if ActiveControl<>"cancel按钮的名字" then exit //注意输入时不要引号哦
    if length(trim(passwordedit.text))<6 then
    begin
      MessageDlg('Password length must greate 6l!',mtInformation,[mbOk],0);
      passwordedit.SetFocus;
    end
      

  4.   

    哦,错了,
    应该为if ActiveControl="cancel按钮的名字" then exit;
      

  5.   

    你可以加一个变量password
    if password then
    begin
    if length(trim(passwordedit.text))<6 then
    begin
      MessageDlg('Password length must greate 6l!',mtInformation,[mbOk],0);
      passwordedit.SetFocus;
      password:=false;
    end
    end;
    然后在passwordedit的onkeypress事件中把password:=true;
      

  6.   

    TO: CoolSlob(夕阳无限好,只是今黄昏----西下夕阳):
    if ActiveControl<>"cancel按钮的名字" then exit //注意输入时不要引号哦
    其中<>要改为=
    谢谢了