tags:

views:

90

answers:

1

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.

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.

This is using Delphi 2010.

+1  A: 

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;

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

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.

Jim McKeeth
I was afraid of that. Perhaps there should be a property of the Action like "ParentRequireFocus" or something to control when it gets triggered.
Alan Clark