Jump to content
Lainkes

Disable Event

Recommended Posts

Hello,


I want to temporary disable an OnExit event on my TEdit component. And then enable it again.

How can I do that?

 

Many thanks

 

Lainkes

 

 

Share this post


Link to post
var
 oldevent : TNotifyEvent;
begin
  oldevent := myComponent.OnExit;
  try
    myComponent.OnExit := nil; 
    
    ..... your code here ...

  finally
    myComponent.OnExit := oldevent ;
  end;
end; 

 

maybe expand the oldevent scope some more if you want to reassign in another method.

 

Edited by mvanrijnen

Share this post


Link to post

Another option is to leave the event handler assigned and use a separate variable instead, eg:

private
  IgnoreExit: Boolean;

...

procedure TMyForm.DoSomething;
begin
  IgnoreExit := True;
  try
    ...
  finally
    IgnoreExit := False;
  end;
end;

...

procedure TMyForm.Edit1Exit(Sender: TObject);
begin
  if IgnoreExit then Exit;
  ...
end;

I like using the component's Tag property for this task, if it is not being used for something else, eg:

procedure TMyForm.DoSomething;
begin
  Edit1.Tag := 1;
  try
    ...
  finally
    Edit1.Tag := 0;
  end;
end;

...

procedure TMyForm.Edit1Exit(Sender: TObject);
begin
  if Edit1.Tag <> 0 then Exit;
  ...
end;

 

Edited by Remy Lebeau
  • Like 1

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

×