[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: 13008
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[RichViewActions] creating your own action

Post by Sergey Tkachenko » Thu Nov 17, 2011 3:38 pm

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: TRVAnsiString;
    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;

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest