我发现了一个解决方法,对我来说足够了;我的主窗体现在覆盖了TCustomForm.IsShortcut()
,并首先从编辑器选项卡列表中检查可见窗口。
我已经方便的列表,所以这可能不适用于所有人。
// Override TCustomForm and make it check the currently focused tab/window first.
function TFormMain.IsShortCut(var Message: TWMKey): Boolean;
function DispatchShortCut(const Owner: TComponent) : Boolean; // copied function unchanged
var
I: Integer;
Component: TComponent;
begin
Result := False;
{ Dispatch to all children }
for I := 0 to Owner.ComponentCount - 1 do
begin
Component := Owner.Components[I];
if Component is TCustomActionList then
begin
if TCustomActionList(Component).IsShortCut(Message) then
begin
Result := True;
Exit;
end
end
else
begin
Result := DispatchShortCut(Component);
if Result then
Break;
end
end;
end;
var
form : TForm;
begin
Result := False;
// Check my menu
Result := Result or (Menu <> nil) and (Menu.WindowHandle <> 0) and
Menu.IsShortCut(Message);
// Check currently focused form <------------------- (the fix)
for form in FEditorTabs do
if form.Visible then
begin
Result := DispatchShortCut(form);
if Result then Break;
end;
//^wont work using GetActiveWindow() because it always returns Self.
// Check all owned components/forms (the normal behaviour)
if not Result then
Result := inherited IsShortCut(Message);
end;
另一种解决方案是改变DispatchShortCut()
检查组件可见和/或启用,但可能会影响比我更想。我怀疑原始代码架构师是否有理由不通过设计。最好是让它调用两次:首先优先考虑可见+启用的组件,然后再调用回退到正常行为。
我想这个新闻组对话关系: http://codeverge.com/embarcadero.delphi.vcl.using/shortcut-problem-suspect-taction/1076571 –
当窗体隐藏,禁止行为管理 –
有不是'TActionManager.Enabled',我必须设置'TAction.Enabled'或使用它的'TAction.OnUpdate()'。 –