首页 > 解决方案 > 带有快捷键 BkSp 的全局 TAction

问题描述

我将 TAction 的 ShortCut 键设置为 BkSp(退格键)。我正在尝试像在网络浏览器中那样实现后退按钮,所以我需要在除编辑控件(TMemo、TEdit 等)之外的任何控件中调用 TAction。

一切都按预期工作,但退格键未发送到编辑控件(因此用户无法删除字符)。

OnExecute 看起来像:

if (Screen.ActiveControl is TCustomMemo) or (Screen.ActiveControl is TCustomEdit) then exit;
DoBack;  

任何想法过去 BkSp 键 trought TAction 编辑控制(所有平台 Win、Mac、Linux)?

标签: pascallazarusmultiplatform

解决方案


解决方案很简单,基于 Andreas Rejbrand 的评论,与 Delphi 中的相同。

在 OnUpdate 上采取行动:

procedure TForm1.aBackUpdate(Sender: TObject); 
begin 
   aBack.Enabled := not (Screen.ActiveControl is TCustomEdit); 
end;

和 OnExecute 采取行动:

procedure TForm1.aBackExecute(Sender: TObject); 
begin 
   DoBack;
end;

推荐阅读