InsertText with RTF Style

General TRichView support forum. Please post your questions here
Post Reply
Thr33D
Posts: 9
Joined: Mon Apr 11, 2011 10:44 am

InsertText with RTF Style

Post by Thr33D »

Hello Sergey,

in my Database, i have saved Text with RTF-Style and now i want insert the Text (with "InsertText(W!?)) from Database into TRichViewEdit.

The Problem is, the Text is not in the RTF-Style assort the Text is in Plantext with all character.

Sample:

That is what we want
H2O

That is what we get with InsertText
H\n6 2\up0 O

Can you help me?

Thanks!
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If this is a RTF fragment, you can make a valid RTF from it (by adding {\rtf1 and }:

Code: Select all

{\rtf1 H\n6 2\up0 O}
save to stream and insert using InsertRTFFromStreamEd.
I can make an example, if you want.

However, is this really RTF? What does '\n6' mean?
Thr33D
Posts: 9
Joined: Mon Apr 11, 2011 10:44 am

Post by Thr33D »

Yes, it is really RTF, i forgot to write all characters. it would be nice if you can make an example how i can save to stream and insertRFTfromstream. many thanks!
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

uses RVTypes;
var s: TRVAnsiString;
    Stream: TMemoryStream;
begin
  s := '{\rtf1 {\fonttbl{\f0 Times New Roman}}Hello \b world!}';
  Stream := TMemoryStream.Create;
  Stream.WriteBuffer(PRVAnsiChar(s)^, Length(s));
  Stream.Position := 0;
  RichViewEdit1.InsertRTFFromStreamEd(Stream);
  Stream.Free;
end;
It is important that \fonttbl contains at least one font. Otherwise TRichView ignores any font attributes (such as \b) and imports all text using RVStyle.TextStyles[0].
It will be changed in the next update: if no fonts is specified in RTF, TRichView will use the font name and charset from RVStyle.TextStyles[0], other properties will be read from RTF (or will be set to defaults for RTF font).
Post Reply