Recent

Author Topic: TRichMemo - idiot question  (Read 3669 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
TRichMemo - idiot question
« 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.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TRichMemo - idiot question
« Reply #1 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

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!
« Last Edit: January 20, 2021, 01:00:01 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

vladimirr

  • New Member
  • *
  • Posts: 29
Re: TRichMemo - idiot question
« Reply #2 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