<< Click to display table of contents >> TCustomRichView.OnSaveComponentToFile |
Occurs when TRichView wants to save inserted control in text, Markdown, RTF, HTML, or DocX file (or stream).
type
TRVSaveComponentToFileEvent = procedure(
Sender: TCustomRichView; Path: TRVUnicodeString;
SaveMe: TPersistent; SaveFormat: TRVSaveFormat;
var OutStr:TRVUnicodeString) of object;
property OnSaveComponentToFile: TRVSaveComponentToFileEvent;
By default, inserted controls are not saved in HTML, RTF, DocX, Markdown, 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, rvsfMarkdown.
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>.
Example:
procedure TMyForm.MyRichViewSaveComponentToFile(
Sender: TCustomRichView; Path: TRVUnicodeString;
SaveMe: TPersistent; SaveFormat: TRVSaveFormat;
var OutStr: TRVUnicodeString);
var bmp: TBitmap;
ImageFileName: TRVUnicodeString;
begin
case SaveFormat of
rvsfText:
begin
if SaveMe is TButton then
OutStr := '['+TButton(SaveMe).Caption+']';
else if SaveMe is TImage then
OutStr := '<Image of '+TImage(SaveMe).Hint+'>';
end;
rvsfHTML:
begin
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='+
TImage(SaveMe).Hint+'>';
bmp.Free;
end;
end;
rvsfRTF:
begin
OutStr := '\plain\b ('+SaveMe.ClassName+')';
end;
end;
end;
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: