I have the code which shows a search form for a specific DBGrid which is placed in another form (the caller Form of TSearchGridForm
):
procedure TSearchGridForm.FormDeactivate(Sender: TObject);
begin
// Pseudo
if NewActiveControl <> CallerForm.DBGrid then
Close;
end;
The TSearchGridForm
is activated by the caller form with .Show
(not Modal) and when it is deactivated I want to close/hide it only if the new active control <> CallerForm.DBGrid
.
Only if the user clicked on DBGrid
on the caller form the search form should remain visible, otherwise I need to close it.
How can I do this?
Delphi's TScreen
object has events OnActiveControlChange and OnActiveFormChange. You can set up event handlers for these to monitor changes and react to them.
See the D7 Online Help for more info. There are Delphi VCL code examples of using both events.