When trying to load an RTF file using RichEdit.Lines.LoadFromFile(FileName)
and RichEdit.ReadOnly = True
the RichEdit removes all images from the RTF file showing an empty placeholder.
Solution:
This is an Embarcadero’s bug. The solution is to call these methods in this specific order with these specific parameters:
procedure TForm2.FormCreate(Sender: TObject);
begin
// Must be False
RichEditEmba.ReadOnly:= FALSE;
// This is irrelevant
RichEditEmba.Transparent:= FALSE;
// Must be False otherwise a 500 pages book does not load at all (program freezes)
RichEditEmba.PlainText:= FALSE;
//The RTF file must be generated by Word !
RichEditEmba.Lines.LoadFromFile('Delphi in all its glory.rtf');
// Now you can make it true (if you want)
RichEditEmba.ReadOnly:= TRUE;
end;
Note that TRichEdit has full support for images from Delphi 11. If you don’t have Delphi 11, an alternative solution I have found is to extract the TJvCustomRichEdit (JvRichEdit.pas) component from Jedi package. I did it. It was a bit of work, but this component functions as it was supposed to: https://github.com/GabrielOnDelphi/RichEdit_Images/
Bonus:
I have managed to insert also tables in the RichEdit.
Also check this extension I wrote for the TRichEdit component, which resizes itself as we add lines to it (instead of showing the vert scrollbars): https://github.com/GabrielOnDelphi/Delphi-LightSaber/blob/main/cvRichEditResize.pas