rvico TRichView Reference | TRichView


Top  Previous  Next

Occurs when RichView wants to save inserted control in text, RTF, HTML, or DocX file (or stream).


  TRVSaveComponentToFileEvent = procedure(

    Sender: TCustomRichView; Path: String;

    SaveMe: TPersistent; SaveFormat: TRVSaveFormat;

    var OutStr:Stringof object;


property OnSaveComponentToFile: TRVSaveComponentToFileEvent;

By default, inserted controls are not saved in HTML, RTF, DocX and text files. But you can use this event to save them.

Input parameters:

SaveMe – component to save.

SaveFormat identifies file format, one of rvsfText, rvsfHTML, rvsfRTF, rvsfDocX.

Path – path where the file is saved. May be used, for example, for saving images (see SavePicture method).

Additional input parameters

Sender.Style.RVData, Sender.Style.ItemNo identify the item to save. RVData document containing item that is being saved; it can be Sender.RVData, table cell, or RVData of cell inplace-editor. ItemNo index of this item inside RVData.

Output parameter:

OutStr – text to insert in the output file.

For Delphi/C++Builder 2009 or newer: OutStr is a Unicode string. For the older versions of Delphi/C++Builder OutStr is an ANSI string.

For DocX, OutStr is inserted inside a "run", i.e. between <w:r> and </w:r>.



procedure TMyForm.MyRichViewSaveComponentToFile(

  Sender: TCustomRichView; Path: String;

  SaveMe: TPersistent; SaveFormat: TRVSaveFormat;

  var OutStr: String);

var bmp: TBitmap;

  ImageFileName: String;


 case SaveFormat of



       if SaveMe is TButton then

         OutStr := '['+TButton(SaveMe).Caption+']';

       else if SaveMe is TImage then

         OutStr := '<Image of '+TImage(SaveMe).Hint+'>';




       if SaveMe is TButton then

         OutStr := '<FORM><INPUT type="button"' +

                   'value="' + TButton(SaveMe).Caption +

                   '" onClick="alert(''Test'')"></FORM>';

       else if SaveMe is TImage then begin

         bmp         := TBitmap.Create;

         bmp.Height  := TImage(SaveMe).Height;

         bmp.Width   := TImage(SaveMe).Width;

         bmp.Canvas.Draw(0,0, TImage(SaveMe).Picture.Bitmap);

         ImageFileName := MyRichView.SavePicture(SaveFormat,Path,bmp);

         OutStr      := '<IMG src="'+ImageFileName+'" alt='+







        OutStr := '\plain\b ('+SaveMe.ClassName+')';




This code saves

TButton controls in text file as "[Button.Caption]" string;

TButton controls in HTML file as form with button;

TImage controls in text file as "<Image of Image.Hint>" string;

TImage controls in HTML file as image (using SavePicture) with alternative text "Image.Hint";

All controls in RTF as "(Class of control)".


See also:


Saving and loading;

Export to HTML.

TRichView © trichview.com