Catch / create OnGetFocus / OnLostFocus events for TCustomControl Delphi

I created a Delphi component inherited from TCustomControl. A component can be concentrated as inherited from TWinControl, but I need to β€œhighlight” it when it focuses and change some properties when it loses focus. As the Delphi documentation says, TCustomControl does not have an OnFocus inherited event, so I need to catch the event (?) And implement my own OnGetFocus / OnLostFocus (?) Event handlers. How can I catch events when a component gains / loses focus?

+6
source share
1 answer

Events triggered when a control gains or loses input focus, OnEnter and OnExit and are fired from DoEnter and DoExit , which you, as a component developer, must override:

 type TMyControl = class(TCustomControl) protected procedure DoEnter; override; procedure DoExit; override; end; implementation { TMyControl } procedure TMyControl.DoEnter; begin inherited; // the control received the input focus, so do what you need here; note // that it recommended to call inherited inside this method (which as // described in the reference should only fire the OnEnter event now) end; procedure TMyControl.DoExit; begin inherited; // the control has lost the input focus, so do what you need here; note // that it recommended to call inherited inside this method (which as // described in the reference should only fire the OnExit event now) end; 
+2
source

Source: https://habr.com/ru/post/989892/


All Articles