Page 1 of 1

InsertText with RTF Style

Posted: Mon Apr 11, 2011 10:55 am
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!

Posted: Mon Apr 11, 2011 3:31 pm
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?

Posted: Mon Apr 11, 2011 5:09 pm
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!

Posted: Mon Apr 11, 2011 5:47 pm
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).