默认的 Edit 操作不适用于TEmbeddedWB
控件,因为该组件不是从TCustomEdit
. TEditAction
,它的TEditSelectAll
后代,只知道如何处理TCustomEdits
。
使用操作的OnUpdate
和OnExecute
事件来覆盖此行为。请注意,默认行为将被忽略,因此请手动实现。这是一个TEditSelectAll
动作的例子。
procedure TForm1.EditSelectAll1Update(Sender: TObject);
begin
EditSelectAll1.Enabled := (Screen.ActiveControl is TEmbeddedWB) or
EditSelectAll1.HandlesTarget(ActiveControl)
end;
procedure TForm1.EditSelectAll1Execute(Sender: TObject);
begin
if ActiveControl is TEmbeddedWB then
TEmbeddedWB(Screen.ActiveControl).SelectAll
else
EditSelectAll1.ExecuteTarget(Screen.ActiveControl);
end;
或者使用 ActionList(或 ApplicationEvents 组件)的相同事件OnActionUpdate
来OnActionExecute
集中此自定义行为:
procedure TForm1.ActionList1Update(Action: TBasicAction; var Handled: Boolean);
begin
if Action is TEditAction then
begin
TCustomAction(Action).Enabled := (Screen.ActiveControl is TEmbeddedWB) or
Action.HandlesTarget(Screen.ActiveControl);
Handled := True;
end;
end;
procedure TForm1.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
begin
if (Action is TEditSelectAll) and (Screen.ActiveControl is TEmbeddedWB) then
begin
TEmbeddedWB(Screen.ActiveControl).SelectAll;
Handled := True;
end;
end;