Search code examples
delphifiremonkeydelphi-11-alexandria

app window detect whether it is in the background in FMX Delphi Windows and Macintosh


My Delphi 11 FMX project has multiple document windows.

How can I detect in code whether or not the window is in the background? (Windows and Macintosh)


Solution

  • The Active: Boolean property indicates whether the form has focus.

    Note, however:

    1. In procedure TCommonCustomForm.Activate; the Active property is set True before OnActivate is called.

    2. In procedure TCommonCustomForm.Deactivate; the Active property is set False after OnDeactivate is called.

    Therefore, referring to the Active property in these events (OnActivate and OnDeactivate) might be error prone. OTOH, the events already tell what the state will be after exit.

    Outside of these events the Active property correctly indicate the actual state.