当在Delphi中可见子窗体时,如何防止执行父窗体中的动作 [英] How to prevent action in parent form executing when child form is visible in Delphi

查看:69
本文介绍了当在Delphi中可见子窗体时,如何防止执行父窗体中的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗体,一个非模态的浮动子窗体.主窗体有一个称为DeleteAction的TAction,它的快捷方式为Delete.当显示浮动表单并按下Delete键时,将执行主表单的DeleteAction.

I have a main form, and a floating child form that is non-modal. The main form has a TAction called DeleteAction that has Delete as it's shortcut. When the floating form is visible and Delete is pressed, the main form's DeleteAction is executed.

如何防止快捷方式通过子表单传递给父表单?我可以验证子表单在该操作的ActionManager的Delete操作的OnExecute处理程序或OnUpdate处理程序中是否没有焦点,但是我还有很多其他操作,因此也必须为他们重复此解决方案.我还有其他可见的浮动形式.

How do I prevent the shortcut passing through the child form to the parent? I could verify that the child form does not have the focus in the Delete action's OnExecute handler or in the OnUpdate handler of the actions's ActionManager, but I have lots of other actions and would have to duplicate this solution for them too. I also have other floating forms that can be visible.

这是使用Delphi 2010.

This is using Delphi 2010.

推荐答案

检查焦点将不起作用,因为在父窗体上按Delete将导致为父窗体赋予焦点.

Checking for focus wouldn't work since pressing Delete on the parent form would result in giving the parent form focus.

function AllowActions: Boolean;
begin
  Result := not ChildFloatingForm.Visible;
end;

然后在操作 OnAction 事件处理程序上,将其 Enabled 属性设置为 AllowActions 的结果;

Then on the actions OnAction event handler, set it's Enabled property to the result of AllowActions;

您还可以将以下行添加到操作的 OnExecute 事件处理程序中:

You could also add the following line to the OnExecute event handler for the action:

if not AllowActions then Exit;

如果您更改了规则,我建议放置关于何时允许操作的规则,因为您说过多个操作可能遵循相同的规则.

I recommend putting the rules about when to allow actions in a function in case you change those rules, and since you said that multiple actions may follow the same rules.

这篇关于当在Delphi中可见子窗体时,如何防止执行父窗体中的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆