I have added hints to components on my form. When the components receive the focus, I’d like to set the caption of a label component to display the hint.
I have added a TApplicationEvents object and set the OnShowHint event to
procedure TImportFrm.ApplicationEvents1ShowHint(var HintStr: string;
var CanShow: Boolean; var HintInfo: THintInfo);
begin
HelpLbl.Caption := HintStr;
end;
However it seems that the ShowHint event only fires with mouse movements. Is there a way to fire the hint code when components receive focus, without having to implement the OnEnter event for every single component on the form?
Add a handler for
TScreen.OnActiveControlChangein your main form’s creation, and handle the hints in that event:Note that
Senderwon’t do you much good; it’s alwaysScreen. You can filter (for instance, to only change theLabel.Captionfor edit controls) by testing theActiveControl:Note that if you’ll need to reassign the event when you show child forms (to an event on that child form), or you’ll always be updating the original form’s label with the hints. The easiest way to do the reassignment is to give every form an
OnActiveControlChangehandler, and assign it in the form’sOnActivateevent and unassign it in theOnDeactivateevent:This will allow you to update controls other than
Label1on each form, and only use the hint changes on forms you want to do so.