Unicode in RichView
|Top Previous Next|
Unicode is a worldwide character-encoding standard. Unicode simplifies localization of software and improves multilingual text processing. By implementing it in an application, a developer can enable the application with universal data exchange capabilities for global marketing, using a single binary file for every possible character code..
For Delphi 2009 or newer, Unicode is a default encoding for strings.
Unicode and ANSI Text in TRichView
All strings in TRichView are Unicode strings.
Import and Export
Note: you can test file with the function
function RV_TestFileUnicode(const FileName: TRVUnicodeString): TRVUnicodeTestResult
defined in RVUni.pas.
▪rvutNo – the file is not Unicode (odd size);
▪rvutYes – the file is most likely Unicode (even size, Unicode byte-order characters at the start or #0 in text (first 500 bytes checked));
▪rvutProbably – the file can contain Unicode (even size);
▪rvutEmpty – the file is empty;
▪rvutError – error opening the file.
You can also use WinAPI function IsTextUnicode performing more advanced tests.
SaveTextW saves Unicode text file. ANSI strings are converted basing on the corresponding Charsets.
RTF (Rich Text Format) and DocX files
RTF and DocX files can contain Unicode text.
SaveHTML*** can save ANSI or Unicode (UTF-8) HTML files. In ANSI HTML files, Unicode characters are written as codes (&#NNNN;), so all Unicode characters are preserved, but file size is increased; so it's highly recommended to save HTML in UTF-8 encoding.
Selection, Search and The Clipboard
GetSelTextW returns selection as a Unicode string.
Text searching methods have versions allowing to search for ANSI and for Unicode string: TRichView.SearchTextA/SearchTextW; however, SearchTextA simply converts the string to Unicode (using Style.DefCodePage) and calls SearchTextW.
CopyTextW copies selection as Unicode.
If pasting text using Paste method, and text is available in Clipboard, the method pastes Unicode text.
InsertTextFromFile: the file must be ANSI (converted, if needed)
InsertOEMTextFromFile: the file must be OEM (converted, if needed)
InsertTextFromFileW: the file must be Unicode (converted, if needed)
RVF (RichView Format)
Applications compiled with older versions of RichView (version less than 1.2) will not be able to load RVF files with Unicode.
RVF files will be loaded correctly even if Unicode flags in text styles are mismatched (saved with different RVStyle then loaded), conversions will be performed if required (for example, this conversion will occur when loading old RVF files in applications compiled in Delphi/C++Builder 2009+). There are two RVF Warnings: rvfwConvToUnicode and rvfwConvFromUnicode, which indicate if any conversion took place.
TRichView v11 introduces a new change in RVF files allowing to store String properties as Unicode. RVF files saved in Delphi/C++Builder 2009+ are saved as RVF version 1.3.1, RVF files saved in the older versions of Delphi/C++Builder are saved as RVF version 1.3.
TRichView © trichview.com