1

The following code works well on D2005 :

  MyRichEdit1.Text := TMemoField(Query1.FieldByName('Msg')).asString;

But in D2010, this code outputs the text in plain text and not on rtf.

To solve the problem I'm using the following code

MyRichEdit1.PlainText := False;
MyRichEdit1.Text := TMemoField(Query1.FieldByName('Msg')).asString;
MyRichEdit1.PlainText := TRUE;
MyRichEdit1.Lines.SaveToFile('Lixo.Rtf');
MyRichEdit1.PlainText := False;
MyRichEdit1.Lines.LoadFromFile('Lixo.Rtf');

How can I import rtf text from a database to a TRichEdit without having to use a file in the process? I tried the solution on this question but it doesn't work, it appear in plain text and with a space between each char.

Thanks Sam

Community
  • 1
  • 1
Sam
  • 53
  • 3
  • it's hard to believe that code would ever have loaded rich text – David Heffernan Jul 27 '11 at 20:14
  • I am migrating from BCB6 to C++ Builder XE and having the same problem. Its really frustrating trying to solve something that could be avoided. Just can't comprehend why the Delphi programmers need to change interface to already functioning thing. – truthseeker Mar 29 '12 at 06:32

2 Answers2

1

If you are trying to load RTF code into a TRichEdit, then place the RTF into a TStream object and use the RichEdit's LoadFromStream() method with the PlainText property set to False.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

This solution is for C++ Builder XE, but analogous could be used for Delphi.

UnicodeString str = L"{\\rtf1 \\qr r{\\sub nom} = ----}"; // some rtf coded text
stream = new TStringStream();
stream->Clear();
stream->WriteString(str);
stream->Seek(0, soFromBeginning);
MyRichEdit1->Lines->LoadFromStream(stream);
delete stream;
stream = NULL;
truthseeker
  • 1,220
  • 4
  • 25
  • 58