The canonical method of displaying hints in a status bar is via the following code:
Constructor TMyForm.Create;
begin
inherited create (nil);
...
Application.OnHint:= MyHint;
...
end;
procedure TMyForm.MyHint (Sender: TObject);
begin
sb.simpletext:= Application.Hint;
end;
procedure TMyForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.OnHint:= nil;
...
end;
The above works fine when a program consists of modal forms, but it is problematic when non-modal forms are used (not necessarily MDI). In these cases, a non-modal form is created and Application.OnHint is assigned to a procedure within the non-modal form; the status bar displays hints from the form. But should another non-modal form be created, Application.OnHint is now assigned to the same procedure within the second form. Moving the mouse over the control with a hint in the first, non-active, form causes that hint to be displayed in the status bar of the second form!
How can I cause each non-modal form to display hints that originate only from its own controls? One possibility is removing hints from controls when a form becomes inactive and restoring them when the form becomes active again, but that is very inelegant. The problem is with the Application.OnHint event.
It turns out that the OP simply wants each form's status bar to display all hints from that form (not minding it also displaying hints from other forms as well).
So this is trivial. Just give all your forms a status bar and drop a
TApplicationEventscomponent onto each form. Create a handler for each component'sOnHintevent:And then everything will just work:
Update
It seems that the OP does mind that. One solution, then, is to do like this:
on all your forms. But only one time do you need to define the helper function
This unfortunately does waste a few CPU cycles, since it calls
FindDragTargetseveral times each timeApplication.Hintis changed, in a sense needlessly since the VCL already has called it once. But this shouldn't be detectable.Update 2
To make this work also for menus (which may also be navigated using the keyboard, in which case the mouse cursor may be anywhere on the screen), I think the following additions will suffice:
Declare a global variable next to the
IsHintForhelper function:and extend this function like so:
Then, to make menu bars work, add the following to each form class with a menu bar:
Finally, to make context menus work, add the following to the unit with the helper function:
Result:
Disclaimer: Not fully tested.