trichview.com

trichview.support




Re: How to insert WideString and RTF code into TRichview


Return to index


Author

Message

Sergey Tkachenko

Posted: 04/27/2003 11:29:48


1) Inserting wide string.


There are several methods for adding Unicode contents in RichView. Please

read "Unicode in RichView" (overview topic in the help file).

For example, methods for inserting Unicode text at the position of caret in

editor:

InsertTextW (inserting multiline text), InsertStringWTag (inserting text

with associated invisible integer/string value).


But work of these functions depends on the active text attributes (current

text style). TRichView document can contain both ANSI and Unicode text.

If current text style is Unicode text, WideString will be inserted as is. If

it is ANSI, string will be converted.


If you want seriously to support Unicode in your application , it's

recommended to use only Unicode text styles:

- in Delphi, at design time, open property editor for TRVStyle.TextStyles,

and set Unicode properties of all predefined text styles to True

- set TRichViewEdit.RTFReadProperties.UnicodeMode to OnlyUnicode.

- if you have existing RichView documents which you want to convert to

Unicode, there is a code in trichview.support.examples how to convert

document to Unicode (I can post it here if you need).


But if you want just to insert separate Unicode symbols, you just need to

ensure that current text style at the moment of insertion is Unicode

Call this procedure before inserting Unicode string:


procedure EnsureUnicode(rve: TCustomRichViewEdit);

var StyleNo: Integer;

    fs: TFontInfo;

begin

  StyleNo := rve.CurTextStyleNo;

  if rve.Style.TextStyles[StyleNo].Unicode then

    exit;

  fs := TFontInfo.Create(nil);

  fs.Assign(rve.Style.TextStyles[StyleNo]);

  fs.Unicode := True;

  StyleNo := rve.Style.TextStyles.FindSuchStyle(StyleNo, fs,

    RVAllFontInfoProperties);

  if StyleNo<0 then begin

    StyleNo := rve.Style.TextStyles.Count-1;

    rve.Style.TextStyles.Add;

    rve.Style.TextStyles[StyleNo].Assign(fs);

    rve.Style.TextStyles[StyleNo].Standard := False;

  end;

  fs.Free;

  rve.CurTextStyleNo := StyleNo;

end;


2) Inserting RTF code (text that will be saved in RTF as is, without

replacing {, }, \ with codes)

You need to include rvteoRTFCode in Options of the text style of inserted

string.

Call this procedure before inserting RTF code string (it is very similar to

the procedure above):


procedure SetRTFCodeStyle(rve: TCustomRichViewEdit);

var StyleNo: Integer;

    fs: TFontInfo;

begin

  StyleNo := rve.CurTextStyleNo;

  if rvteoRTFCode rve.Style.TextStyles[StyleNo].Options then

    exit;

  fs := TFontInfo.Create(nil);

  fs.Assign(rve.Style.TextStyles[0]);

  fs.Options := fs.Options + [rvteoRTFCode];

  fs.BackColor := clYellow;

  StyleNo := rve.Style.TextStyles.FindSuchStyle(StyleNo, fs,

    RVAllFontInfoProperties);

  if StyleNo<0 then begin

    StyleNo := rve.Style.TextStyles.Count-1;

    rve.Style.TextStyles.Add;

    rve.Style.TextStyles[StyleNo].Assign(fs);

    rve.Style.TextStyles[StyleNo].Standard := False;

  end;

  fs.Free;

  rve.CurTextStyleNo := StyleNo;

end;


This procedure constructs and uses a text style having all properties of the

0-th text style (which  in many cases is used as a default style), but with

RTFCode option and with yellow background.

Using:

SetRTFCodeStyle(RichViewEdit1);

RichViewEdit1.InsertText('\animtext1 Viva Las Vegas');






>

> Hi,

>

> I found no way to insert WideString and RTF code into TRichview,

> Could you please tell me how to do it ?

>

>





Powered by ABC Amber Outlook Express Converter