app window 在 FMX Delphi Windows 和 Macintosh 中检测是否在后台

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

我的Delphi11 FMX项目有多个文档windows。

如何在代码中检测 window 是否在后台? (Windows 和 Macintosh)

Active: Boolean 属性表示表单是否有焦点。

但是请注意:

  1. 在程序 TCommonCustomForm.Activate;Active 属性 设置 True before OnActivate 被调用。

  2. 在程序 TCommonCustomForm.Deactivate; 中设置 Active 属性 False after OnDeactivate 被调用。

因此,在这些事件中引用 Active 属性 OnActivateOnDeactivate 可能容易出错. OTOH,事件已经说明了退出后的状态。

除了这些 事件之外,Active 属性 正确指示实际状态。