tags:

views:

117

answers:

3

I open forms inside tabs of a page control. These forms may contain actions with shortcuts. And I want these shortcuts to be fired only when the tab that contain this form is active.

I tried to override form's IsShortCut but it's not called. Form's OnShortCut is not called either.

I would like to avoid putting code on each action to check this.

I'm using Delphi 2010.

A: 

Try setting the form's Enabled to false whan you switch away, and True when you switch onto it's tab. That should disable all the content on the form, including shortcuts.

Mason Wheeler
I am not sure if this will work, for if a TButton on the TTabSheet is controlled by a TAction, then disabling the TTabSheet (and hence the TButton), will not automatically disable the TAction.
Andreas Rejbrand
I'm assuming, from the description, that he's parenting actual TForm descendants onto the tab sheets. If not, then my answer's probably invalid.
Mason Wheeler
You were right! :)
Andreas Rejbrand
+2  A: 

Set the State for the action lists on your hidden tabs to asSuspended. Only the action list on your visible tab should have a state of asNormal. That will prevent the shortcut keys from working. It also prevents those actions from updating, which may or may not be a good thing for your application.

afrazier
A: 

Put all the shortcuts into actions and those actions into one action list per form. Then you can disable the action lists of the forms that are currently not active. (I don't recall the exact TActionList property to set or method to call or activating/deactivating it, but it is there.)

dummzeuch