4

I am generally satisified with functionality of TEditCut, TEditCopy, TEditPaste and TEditSelectAll except they don't work on any controls which are not standard.

For example, they may work fine on TEdit or TMemo controls, but not on TEmbeddedWB — with it, standard actions are always disabled regardless of whether text is selected, even though TEmbeddedWB has methods like CopyToClipboard and SelectAll.

How can I make standard actions work with TEmbeddedWB? How do standard actions determine whether they should be enabled or disabled (and in what event they do it — is it in the OnUpdate event)? Can I extend standard actions to add support for unrecognized components, or do I need to write their replacement?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Coder12345
  • 3,431
  • 3
  • 33
  • 73

1 Answers1

6

The default Edit actions do not work on a TEmbeddedWB control, because that component does not descend from TCustomEdit. TEditAction, which TEditSelectAll descends from, only knows how to handle TCustomEdits.

Use the OnUpdate and OnExecute events of the action to override this behaviour. Note that the default behaviour then will be ignored, so implement that manually. Here an example for a TEditSelectAll action.

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;

Or use the same events of the ActionList (or OnActionUpdate and OnActionExecute of an ApplicationEvents component) to centralize this custom behaviour:

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;
NGLN
  • 43,011
  • 8
  • 105
  • 200