Lainkes 0 Posted August 24, 2022 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
dummzeuch 1505 Posted August 24, 2022 Assign NIL to it and later reassign the original event. Share this post Link to post
Lainkes 0 Posted August 24, 2022 Maybe stupid question, but how do I reassign the original event? Lainkes Share this post Link to post
mvanrijnen 123 Posted August 24, 2022 (edited) 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 August 24, 2022 by mvanrijnen Share this post Link to post
Lainkes 0 Posted August 24, 2022 Thanks, this seems to work fine. Lainkes Share this post Link to post
Remy Lebeau 1394 Posted August 24, 2022 (edited) 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 August 24, 2022 by Remy Lebeau 1 Share this post Link to post