[RichViewActions] creating your own action
Posted: 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:
Updates:
2018-Apr-12: changes for compatibility with TRichView 17.3 (for older versions of TRichView, change the type of s variable to TRVAnsiString)
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;
2018-Apr-12: changes for compatibility with TRichView 17.3 (for older versions of TRichView, change the type of s variable to TRVAnsiString)