3

When I try to load an RTF file using RichEdit1.Lines.LoadFromFile(FilePath) method and RichEdit1.ReadOnly = True then the RichEdit removes all images from the RTF file and shows an empty area in their place:

image

procedure TForm1.Button1Click(Sender: TObject);
var
  BasePath: String;
  FilePath: String;
begin
  GetDir(0, BasePath);
  FilePath := BasePath + '\TestRtfFileMS.Rtf';

  RichEdit1.Lines.LoadFromFile(FilePath);

  RichEdit2.ReadOnly := True;
  RichEdit2.Lines.LoadFromFile(FilePath);
end;

How do I fix this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
DmitryB
  • 455
  • 1
  • 5
  • 18
  • That sounds like a bug to me. You should report it on https://quality.embarcadero.com/login.jsp – HeartWare Mar 28 '22 at 05:21
  • 2
    Which version of Delphi are you using? – Remy Lebeau Mar 28 '22 at 05:23
  • 2
    If I create an RTF file with an image in WordPad, the image is always lost when I open the RTF document in the `TRichEdit` control. But if I create an "identical" document in Word 2010, the image is indeed shown in the `TRichEdit` control, but fails to load if `ReadOnly = True`, as discovered by the OP. Remy's question is also very relevant, since the `TRichEdit` was rather heavily updated in Delphi 11. – Andreas Rejbrand Mar 28 '22 at 07:59
  • 1
    (joking) Pictures are not text, so `.ReadOnly` has to be taken literally and works as intended: just text remains. – AmigoJack Mar 28 '22 at 10:02
  • I tested in RAD Studio 11 Version 28.0.44500.8973 – DmitryB Mar 28 '22 at 15:51
  • @DmitryB Just to check - do you have `RichEdit1.PlainText` set to `True` or `False`? It must be `False` to load RTF content. – Remy Lebeau Mar 30 '22 at 18:21
  • Same behavior on DevExpress version of RichEdit. Can be depend on some policy? Wordpad asterisk me during opening - if check "unblock" picture is visible. Otherwise no. – Dżyszla Apr 07 '23 at 11:18

0 Answers0