TRichViewEdit LoadRTFFromStream add an empty line

General TRichView support forum. Please post your questions here
Post Reply
Fab85
Posts: 17
Joined: Tue Apr 09, 2024 6:02 am

TRichViewEdit LoadRTFFromStream add an empty line

Post 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?
Attachments
LineJump.png
LineJump.png (14.87 KiB) Viewed 4762 times
LineJump.zip
(12.27 KiB) Downloaded 47 times
Sergey Tkachenko
Site Admin
Posts: 17651
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit LoadRTFFromStream add an empty line

Post 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.
Fab85
Posts: 17
Joined: Tue Apr 09, 2024 6:02 am

Re: TRichViewEdit LoadRTFFromStream add an empty line

Post 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!
Post Reply