Jump to content
Registration disabled at the moment Read more... ×
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×