[RichViewActions] creating your own action

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

[RichViewActions] creating your own action

Post by Sergey Tkachenko »

This example shows how to create your own RichViewAction basing on TrvActionEvent.

This example shows how to implement a simple action displaying information about the current picture in the document.

1. In Delphi IDE, open the ActionList's editor, choose "New Standard Action..." command. Select "RVE Custom | TrvActionEvent.
2. For this action, assign Name='Image Information', Hint='Image Information|Displays the image type and size'.
3. Assign events - OnUpdate and OnExecute:

Code: Select all

procedure TrvActionsResource.rvActionEvent1Execute(Sender: TObject;
  Editor: TCustomRichViewEdit);
var gr: TGraphic;
    Tag: TRVTag;
    Align: TRVVAlign;
    s: TRVUnicodeString;
    info: String;
begin
  Editor.GetCurrentPictureInfo(s, gr, Align, Tag);
  info := Format('%s %dx%d', [gr.ClassName, gr.Width, gr.Height]);
  Application.MessageBox(PChar(info), 'Image Info', MB_OK or MB_ICONINFORMATION);
end;

procedure TrvActionsResource.rvActionEvent1Update(Sender: TObject;
  Editor: TCustomRichViewEdit);
var CurStyleNo: Integer;
begin
  CurStyleNo := Editor.CurItemStyle;
  (Sender as TrvActionEvent).Enabled := (CurStyleNo=rvsPicture) or
    (CurStyleNo=rvsHotPicture);
end;
Updates:
2018-Apr-12: changes for compatibility with TRichView 17.3 (for older versions of TRichView, change the type of s variable to TRVAnsiString)
Post Reply