|
TCustomRichView.OnSaveItemToFile |
Top Previous Next |
|
Allows you to change how document items are saved in text, RTF or HTML file or stream. type TRVSaveItemToFileEvent = procedure (Sender: TCustomRichView; const Path: String; RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; Unicode: Boolean; var OutStr:String; var DoDefault: Boolean) of object; (introduced in v1.8) This is a "low level" event allowing to change saving of items completely. There are events offering a subset of functionality of this event: These events are easier to use than this event.
Input parameters: Path – path to output file; RVData, ItemNo – 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. SaveFormat identifies file format, one of rvsfText, rvsfHTML, rvsfRTF. Unicode – True when saving Unicode text files or UTF-8 HTML files. Text:
DoDefault – True.
Output parameters: Set values of DoDefault and Text according to the table below. Mismatched values will cause corrupted files.
If you do not want to change saving of some item, leave DoDefault to True. You cannot override some special processing for paragraph markers when saving to HTML and RTF.
Example 1: saving text items in UTF-8 encoding in HTML and text files. In this example, we change default saving only if Unicode parameter is False (it is equal to False when saving ANSI text or HTML files). uses RVUni, CRVData;
procedure TMyForm.MyRichViewSaveItemToFile( Sender: TCustomRichView; const Path: String; RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; Unicode: Boolean; var Text: String; var DoDefault: Boolean); begin if (SaveFormat in [rvsfText, rvsfHTML]) and (RVData.GetItemStyle(ItemNo)>=0) and not Unicode then begin if Sender.Style.TextStyles[RVData.GetItemStyle(ItemNo)].Unicode then Text := UTF8Encode(RVU_RawUnicodeToWideString(Text)) else Text := AnsiToUtf8(Text); DoDefault := False; end; end; Note 1: For HTML files, there is an option for saving as UTF-8, so this code is given only as an example. This example is imperfect, because:
Note 2: One more simplification: AnsiToUtf8 uses a system default code page for converting ANSI to Unicode (for better results, languages (Charsets) of text items must be taken into account for the conversion). Example 2: saving pictures as '<PIC>' (in text files, HTML and RTF) procedure TMyForm.MyRichViewSaveItemToFile( Sender: TCustomRichView; const Path: String; RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; Unicode: Boolean; var Text: String; var DoDefault: Boolean); begin if (RVData.GetItemStyle(ItemNo)=rvsPicture) then begin if SaveFormat=rvsfHTML then Text := '<PIC>' else Text := '<PIC>'; if Unicode then Text := RVU_GetRawUnicode(Text); DoDefault := False; end; end; Note: for non-text items, Text is saved as it is; so we need to replace '<' with '<' and '>' with '>' for HTML. | ||||||||||||||||||||||||||||||