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

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 13468
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko » Thu Nov 18, 2010 3:59 pm

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;
Last edited by Sergey Tkachenko on Wed Jun 05, 2013 5:24 am, edited 4 times in total.

Sergey Tkachenko
Site Admin
Posts: 13468
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Nov 18, 2010 4:02 pm

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;

Sergey Tkachenko
Site Admin
Posts: 13468
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Fri Jun 07, 2013 2:55 pm

ScaleRichView example is updated for compatibility with TRichView 14.5+

Post Reply