Page 1 of 1

TRichViewEdit LoadRTFFromStream add an empty line

Posted: Wed Jan 22, 2025 9:04 am
by Fab85
Hello,

I am testing TRichViewEdit, and I encountered an issue where it seems to add an unwanted line break at the first line. Below is the code I used for testing:

Code: Select all

procedure TForm17.FormShow(Sender: TObject);
var
  LTextString:TStringstream;
begin
   LTextString:= TStringstream.create;
   try
    LTextString.WriteString(
        '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1036{\fonttbl{\f0\fnil\fcharset0 Calibri;}}'
        +'{\*\generator Riched20 10.0.22621}\viewkind4\uc1'
        +'\pard\sa200\sl276\slmult1\f0\fs22\lang12 Line 1\par'
        +'}'
        );

      LTextString.Position:=0;
      RichViewEdit1.LoadRTFFromStream(LTextString);
      RichViewEdit1.ReformatAll;  // same with RichViewEdit1.Reformat
   finally
      LTextString.free;
   end;


end;
My RichViewEdit1 component is a default TRichViewEdit, and no properties were modified. However, when loading the RTF content, a line jump is added at the beginning of the text.

I am attaching a screenshot and the full source code for reference.

Environment:
Delphi 11.3 and 12.2 VCL
TRichView version 23

Could you please let me know why this happens and how to resolve it?

Re: TRichViewEdit LoadRTFFromStream add an empty line

Posted: Wed Jan 22, 2025 11:21 am
by Sergey Tkachenko
Formatted TRichViewEdit control initially contains one empty text line.
LoadRTFFromStream does not clear document before loading, it appends content to the end.
Just call Clear before LoadRTFFromStream.

Re: TRichViewEdit LoadRTFFromStream add an empty line

Posted: Wed Jan 22, 2025 11:40 am
by Fab85
Hello Sergey,

I fell into the trap because, in most cases, a LoadFromStream (Tmemo, Trichedit) operation clears the destination content. However, you clearly mentioned this in the documentation, and I missed it :roll: .

Thank you for your quick and efficient response—it’s greatly appreciated!