I want my control to receive distinct notifications only when it's parent form (not panel or something else, just the main form of this control) receives and loses focus. Doesn't matter if the focus is switched from another form of the application or between my application and other application, it must be received for both cases. Is it possible? I want to suspend some updates of the control when his form is not active and resume the updates when the form is activated.
Edit: In other words, the control must catch the (TForm.OnActivate
+ TApplication.OnActivate
) and (TForm.OnDeactivate
+ TApplication.OnDeactivate
)
Edit2: If it's not possible both, at least if I can make the control catch the events from TApplication. It's more important than those from TForm.
If those updates are done continuously, or are being triggered by a timer or actions, then you could be done with:
Catching
TApplication.OnActivate
andTApplication.OnDeactivate
is pretty easy with aTApplicationEvents
component:Catching the (de)activation of the parenting form can be done in
Application.OnIdle
. All this combined could result in something like this:Because using
Application.OnIdle
is quite a rigorous method, spare its use like I did above by only assigning it when necessary and speed up its implementation by caching function results likeGetParentForm
.