Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何使标准操作(如TEditCopy)识别其他控件(如TEmbeddedWB)?_Delphi_Webbrowser Control_Action_C++builder_Twebbrowser - Fatal编程技术网

Delphi 如何使标准操作(如TEditCopy)识别其他控件(如TEmbeddedWB)?

Delphi 如何使标准操作(如TEditCopy)识别其他控件(如TEmbeddedWB)?,delphi,webbrowser-control,action,c++builder,twebbrowser,Delphi,Webbrowser Control,Action,C++builder,Twebbrowser,我通常对TEditCut、TEditCopy、TEditPaste和TEditSelectAll的功能感到满意,但它们不适用于任何非标准控件 例如,它们可以在TEdit或TMemo控件上正常工作,但不能在TEmbeddedWB上正常工作-使用它,无论文本是否被选中,标准操作始终处于禁用状态,即使TEmbeddedWB具有CopyToClipboard和SelectAll等方法 如何使标准操作与TEmbeddedWB一起工作?标准操作如何确定应启用还是禁用它们(以及在什么情况下启用-是否在OnUp

我通常对
TEditCut
TEditCopy
TEditPaste
TEditSelectAll
的功能感到满意,但它们不适用于任何非标准控件

例如,它们可以在
TEdit
TMemo
控件上正常工作,但不能在
TEmbeddedWB
上正常工作-使用它,无论文本是否被选中,标准操作始终处于禁用状态,即使
TEmbeddedWB
具有
CopyToClipboard
SelectAll
等方法


如何使标准操作与
TEmbeddedWB
一起工作?标准操作如何确定应启用还是禁用它们(以及在什么情况下启用-是否在
OnUpdate
事件中)?我是否可以扩展标准操作以添加对无法识别组件的支持,或者我是否需要编写它们的替换项?

默认编辑操作在
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;

谢谢,这看起来正是我需要处理的。