Lazarus

Programming => Packages and Libraries => RichMemo => Topic started by: mtanner on January 20, 2021, 11:43:23 am

Title: TRichMemo - idiot question
Post by: mtanner on January 20, 2021, 11:43:23 am
I have just started using TRichMemo. I load text into the RTF field, and it gets displayed ok, with line breaks automatically adjusting when the TRichMemo is resized. So far so good.

I thought I would be able to put RTF markup tags within the text and get the text formatted when displayed by the TRichMemo. That doesn't happen, so I must have misunderstood something. How do I get RTF markup to work?

My basic test is to put \par...\pard around some text in the RTF field, but those tags just get displayed as text.
Title: Re: TRichMemo - idiot question
Post by: lucamar on January 20, 2021, 12:57:37 pm
To add "markup" you have to use the several properties that deal with it: paragraph alignment. bullets, bold text, etc. You don't just add the tags to the text and hope they get re-interpreted. See how it's done in the wiki: RichMemo (https://wiki.freepascal.org/RichMemo)

To do what you want you'd have to open the rtf file as a text file using a plain-text edit control like, say. a TMemo, and use the TRichMemo only to display the result.

HTH!
Title: Re: TRichMemo - idiot question
Post by: vladimirr on January 21, 2021, 12:20:02 pm
Code: Pascal  [Select][+][-]
  1. const
  2.   rtf_open = '{\rtf1\ansi ';
  3.   rtf_close = '}';
  4.  
  5. procedure TForm1.Button1Click(Sender: TObject);
  6. var
  7.   Stream : TMemoryStream;
  8.   Source : string;
  9. begin
  10.   Source := rtf_open + 'Some \par text.' + rtf_close;
  11.   Stream := TMemoryStream.Create;
  12.   Stream.WriteBuffer(Pointer(Source)^, Length(Source));
  13.   Stream.Seek(0,soFromBeginning);
  14.   RichMemo1.LoadRichText(Stream);
  15.   Stream.Free;
  16. end;
  17.  
TinyPortal © 2005-2018