Question: I have a main form and a secondary form both with some DBAware controls from a common database. Currently I am using ShowModal but I would like to be able to use Modal to go back to the main form and navigate the database.

In the secondary I can replace the TDBEdits with TEdits and stuff them with data when I Show the secondary form. There is no means of navigating the database in the secondary form, but, if the user can go back to the main form where they can navigate, I will need to reset the database cursor when they return to the secondary.

How can I tell that the secondary form has just lost focus? I can grab the database cursor position.

How can I tell when the secondary form gets focus again? So I can reset the database cursor if it was moved before returning.

Thanks
p.s. Please no questions on why and/or alternative suggestions. It is an existing application and I really do not want to have to fix miles of code. As crappy as it is, it has been working for years and the customer wants the change of possible. :)

Answer: 
Use the form's `OnActivate` and `OnDeactivate` events. `OnActivate` is called when the form gains focus, and `OnDeactivate` is called when it loses it.

Note that these events are only triggered when focus is transferred within your own application. If you need to know when your application itself loses or gains focus, use `TApplication.OnActivate` and `TApplication.OnDeactivate` instead.
You can take a look at the `onActivate` and `onDeactivate` events of the secondary form. I think they are what you need.

**Note**: OnDeactivate works only if focus is switched to another form of project. For example I have project1.exe which creates 2 forms Form1 and Form2 . So Form1 OnDeactivate event triggers if I ckick Form2. But it will not be trigger if I click Notepad window.