When I place a TRibbon control on a form that is not the MainForm of the application, that TRibbon's actions (i.e. Cut, Paste) will always return focus to the MainForm after the action is executed.
This occurs even if the TForm that holds the TRibbon is not a child of the MainForm.
I am using Windows 7 64-bit, Embarcadero RAD Studio XE Version 15.0.3953.35171.
Am I using the TRibbon control incorrectly, or is this an issue with the TRibbon?
This is evidently by design. Sample code snippet from 'ribbonactnctrls.pas':
As you see there are no conditions checked that would help us avoid the call. There's the same code also in menu item selection and key press handlers.
I would probably modify the source commenting the focus calls, and try to see if there're any side effects.
As an alternative you can restore the focus back to your form after it is switched to the main form. Suppose 'ActionList1' is the TActionList that contains standard actions on the not main form:
This will however cause the main form to flash briefly every time an action is executed. If you don't want that, you can change the design so that the main form knows when it is getting an unwanted focus, and fake that it's not focused.
In unit1:
in unit2:
However, this is not enough if you don't have 'MainFormOnTaskBar' set in project source, since then the main form will not only gain focus but will be brought to front. In this case both forms could respond to the unwanted focus change/activation by freezing their z-orders. The code would then become for unit1:
and for unit2: