|
TCustomRichView.OnSaveComponentToFile |
Top Previous Next |
|
Occurs when RichView wants to save inserted control in text, RTF or HTML file. type TRVSaveComponentToFileEvent = procedure( Sender: TCustomRichView; Path: String; SaveMe: TPersistent; SaveFormat: TRVSaveFormat; var OutStr:String) of object;
property OnSaveComponentToFile: TRVSaveComponentToFileEvent; By default, inserted controls are not saved in HTML, RTF 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. Path – path where the file is saved. May be used, for example, for saving images (see SavePicture method). Output parameter: OutStr – text to insert in the output file. This is a Unicode string for Delphi/C++Builder 2009 or newer, and ANSI string for the older versions of Delphi/C++Builder.
Example: procedure TMyForm.MyRichViewSaveComponentToFile( Sender: TCustomRichView; Path: String; SaveMe: TPersistent; SaveFormat: TRVSaveFormat; var OutStr: String); var bmp: TBitmap; ImageFileName: String; 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: |