<< Click to display table of contents >>


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


  TRVSaveComponentToFileEvent = procedure(

    Sender: TCustomRichView; Path: TRVUnicodeString;

    SaveMe: TPersistent; SaveFormat: TRVSaveFormat;

    var OutStr:TRVUnicodeStringof 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 DocX, OutStr is inserted inside a "run", i.e. between <w:r> and </w:r>.



procedure TMyForm.MyRichViewSaveComponentToFile(

  Sender: TCustomRichView; Path: TRVUnicodeString;

  SaveMe: TPersistent; SaveFormat: TRVSaveFormat;

  var OutStr: TRVUnicodeString);

var bmp: TBitmap;

  ImageFileName: TRVUnicodeString;


 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.