Page 1 of 1

[How to] How to use actions in DLL or ActiveX

Posted: Thu Nov 18, 2010 3:59 pm
by Sergey Tkachenko
Warning: using TRichView/ScaleRichView in DLL or ActiveX requires a special permission from us, see the license:
- in trial: ReadMe.chm | License
- in full version: Install.chm | License


In a normal application, a state of all actions (Enabled, Checked) is updated periodically when this application is idle.
In DLL or ActiveX, it does not happen.

The solution is creating a timer and calling UpdateTarget in OnTimer.

1) Example for TRichViewEdit.
This example assumes that all actions work with RichViewEdit1, and all of them are placed on rvActionsResource datamodule.

Place Timer1: TTimer on the form.
Assign Timer1.Interval = 300.
Timer1.OnTimer:

Code: Select all

procedure TForm3.Timer1Timer(Sender: TObject);
var i: Integer;
begin
  for i := 0 to rvActionsResource.ComponentCount-1 do
     if rvActionsResource.Components[i] is TAction then
       TAction(rvActionsResource.Components[i]).UpdateTarget(RichViewEdit1);
end;
Create a new form's procedure:

Code: Select all

procedure TForm3.DoActionsExecute(Sender: TObject);
begin
  TAction(Sender).ExecuteTarget(RichViewEdit1);
end;
In FormCreate, assign this procedure to OnExecute of all actions:

Code: Select all

  for i := 0 to rvActionsResource.ComponentCount-1 do
    if rvActionsResource.Components[i] is TAction then
      TAction(rvActionsResource.Components[i]).OnExecute := DoActionsExecute;

Posted: Thu Nov 18, 2010 4:02 pm
by Sergey Tkachenko
2) Example for TSRichViewEdit (ScaleRichView).

The idea is the same, but there is an additional difficulty in finding the proper control to pass as the parameter of UpdateTarget and ExecuteTarget.

This example assumes that all actions work with SRichViewEdit1, and all of them are placed on srvActionsResource datamodule.

Code: Select all

type
  TrvActionAccess = class(TrvAction);

// Updated 2013-06-05: changed for compatibility with TRichView 14.5
function TForm3.GetRVAControlFor(Action: TAction): TControl;
begin
    Result := SRichViewEdit1
end;

procedure TForm3.Timer1Timer(Sender: TObject);
var i: Integer;
begin
  for i := 0 to srvActionsResource.ComponentCount-1 do
     if srvActionsResource.Components[i] is TAction then
       TAction(srvActionsResource.Components[i]).UpdateTarget(GetRVAControlFor(TAction(srvActionsResource.Components[i])));
end;

procedure TForm3.DoActionsExecute(Sender: TObject);
begin
  TAction(Sender).ExecuteTarget(GetRVAControlFor(TAction(Sender)));
end;
In FormCreate:

Code: Select all

  for i := 0 to srvActionsResource.ComponentCount-1 do
    if srvActionsResource.Components[i] is TAction then
      TAction(srvActionsResource.Components[i]).OnExecute := DoActionsExecute;

Posted: Fri Jun 07, 2013 2:55 pm
by Sergey Tkachenko
ScaleRichView example is updated for compatibility with TRichView 14.5+