This information is about TRichView versions prior to 17.3. Information about TRichView 17.3 and newer is in the next post.
How to make Unicode editor in TRichView v11 or newer in Delphi 4-2007
1) Set Unicode property to True for all TextStyles in TRVStyle.
2) Set RichViewEdit1.RTFReadProperties.UnicodeMode = rvruOnlyUnicode.
3) Methods working with text usually have 3 variants: default (e.g. SetItemText), A-method (e.g. SetItemTextA), W-method (e.g. SetItemTextW). All methods can be used for Unicode text, but to avoid losses and unnecessary conversions use W-methods.
4) Existing non-Unicode RVF documents must be converted to Unicode by calling ConvertToUnicode after loading them (see below).
Code: Select all
uses CRVData, RVItem, RVUni;
// changes required for TRichView v11+ are marked with red
procedure ConvertRVToUnicode(RVData: TCustomRVData);
var i,r,c, StyleNo: Integer;
table: TRVTableItemInfo;
begin
for i := 0 to RVData.ItemCount-1 do begin
StyleNo := RVData.GetItemStyle(i);
if StyleNo>=0 then begin
if not RVData.GetRVStyle.TextStyles[StyleNo].Unicode then begin
RVData.SetItemText[color=red]R[/color](i, RVU_GetRawUnicode(RVData.GetItemTextW(i)));
Include(RVData.GetItem(i).ItemOptions, rvioUnicode);
end;
end
else if RVData.GetItemStyle(i)=rvsTable then begin
table := TRVTableItemInfo(RVData.GetItem(i));
for r := 0 to table.Rows.Count-1 do
for c := 0 to table.Rows[r].Count-1 do
if table.Cells[r,c]<>nil then
ConvertRVToUnicode(table.Cells[r,c].GetRVData);
end;
end;
end;
procedure ConvertToUnicode(rv: TCustomRichView);
var i: Integer;
begin
ConvertRVToUnicode(rv.RVData);
for i := 0 to rv.Style.TextStyles.Count-1 do
rv.Style.TextStyles[i].Unicode := True;
end;
How to make Unicode editor in TRichView v11 or newer in Delphi 2009 or newer
1) Unicode property of text styles and RTFReadProperties.UnicodeMode property of TRichView have the proper values by default. If you convert old projects, check them.
2) Methods working with text usually have 3 variants: default (e.g. SetItemText), A-method (e.g. SetItemTextA), W-method (e.g. SetItemTextW). Default method work with String, so you can use them for Unicode text.
2) Existing RVF documents saved by applications compiled with older versions of Delphi are automatically converted to Unicode when loading.
For all versions of Delphi
There are some events having TRVRawByteString parameters: OnItemAction, OnReadHyperlink, OnRVDblClick, OnRVRightClick, OnSaveItemToFile, OnItemTextEdit, OnDrawStyleText.
These parameters contain text in internal representation. For Unicode text, this is a "raw Unicode", with each Unicode character represented by 2 adjacent 1-byte characters.
You can use this function to convert them to String:
Code: Select all
uses RVTypes, RVUni;
{$I RV_Defs.inc}
// Converting text from internal representation to String
function ConvertItemTextToString(const ItemText: TRVRawByteString;
UnicodeItem: Boolean; CodePage: Cardinal): String;
begin
{$IFDEF RVUNICODESTR} // <-- declared in RV_Defs.inc
// Delphi 2009+: String is Unicode
if UnicodeItem then
Result := RVU_RawUnicodeToWideString(ItemText)
else
Result := RVU_RawUnicodeToWideString(
RVU_AnsiToUnicode(CodePage, ItemText));
{$ELSE}
// Delphi 4-2007: String is ANSI
if UnicodeItem then
Result := RVU_UnicodeToAnsi(CodePage, ItemText)
else
Result := ItemText;
{$ENDIF}
end;
ItemText - text to convert.
UnicodeItem - pass True if this text is from Unicode text item.
CodePage - code page for conversion, you can use RVStyle1.DefCodePage.
Additional information:
http://www.trichview.com/help/index.htm ... hview.html