Jump to content
Ian Branch

Block Component Exit Event on Cancel?

Recommended Posts

Hi Team,

I have the following procedure.

procedure TLogInForm.edtUserIDExit(Sender: TObject);
begin
  //
  if Trim(edtUserID.Text) = '' then
  begin
    TaskMessageDlg('User ID Error!', 'A User ID is required to be entered.', mtError, [mbOK], 0);
    edtUserID.SetFocus;
  end;
  //
end;

The procedure is in a home brew Log in Dialog. 

It works fine, with one exception, If I click Cancel on the form and edtUserID is empty, of course the event fires.

How do I bypass/negate the event if btnCancel is clicked when edtUserID is empty?

 

Regards & TIA,

Ian

Share this post


Link to post

My uses are to do all controls at the exit of the dialogs. In that point I can control all (for example incompatibility between choose selection or settings, set value, etc ...) and report to user what he should do.

I really don't know how to resolve your issue.

Share this post


Link to post

You really shouldn't prevent the user from moving the focus; It's one of the most annoying ways to do validation.

 

Instead do your validation in the OK handler. If you use TActionList you can also do the validation in the OnUpdate event handler and only enable the OK button when all validations pass.

If you want to be really nice to your users do the validation while they are entering data but instead of blocking them just indicate errors with color or a symbol.

  • Like 2

Share this post


Link to post

Hi Guys,

Thank you for your inputs.

I have moved the handling to the OK button.

All good now.

 

Regards,

Ian

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×