Why TRichEdit removes images from a loaded file when TRichEdit.ReadOnly?

360 Views Asked by At

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?

1

There are 1 best solutions below

0
On

I solved it as follows.

  1. First, write the *.rtf file containing the image in the "Word". (It should Not be written in the "Wordpad".)

  2. At runtime, the rtf file is imported into TRichEdit and set to ReadOnly = True. (Not desigetime)

.

RichEdit1.Lines.LoadFromFile('myFile.rtf');
RichEdit1.ReadOnly := True;