InsertRVFFromStream extra line at end

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

InsertRVFFromStream extra line at end

Post by standay »

Hi Sergey,

When I use rve.InsertRVFFromStream, I always seem to get an extra line at the end of the doc. Here's the code:

Code: Select all

  ActiveRVE.SaveRVFToStream(Stream,false);
  Stream.Position := 0;
  ActiveRVE.Clear;
  RVStyle1.ResetParaStyles;
  RVStyle1.ListStyles.Clear;
  ActiveRVE.DeleteUnusedStyles(true,true,true);
  //ActiveRVE.Format; //call this *after* deleting unused styles

  ActiveRVE.InsertRVFFromStream(Stream,0);
  ActiveRVE.DeleteUnusedStyles(true,true,true);
  //ActiveRVE.Format; //call this *after* deleting unused styles
I had to add the following to compensate for this:

Code: Select all

  if ActiveRVE.ItemCount-1 > 0 then
    ActiveRVE.DeleteItems(ActiveRVE.ItemCount-1,1);
  ActiveRVE.Format;
Is there another way to call InsertRVFFromStream or some other or better way to handle that extra line or item or whatever it is that always seems to be added?

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: InsertRVFFromStream extra line at end

Post by Sergey Tkachenko »

Sorry for the delay.

1) InsertRVFFromStream is not an editing-style method; it simply inserts content at the specified position.
And it does not reformat the affected part of the document; that means that the final call of Format is necessary.
2) When you format an empty TRichViewEdit, a blank line is added.

As a result:
When you call Format before InsertRVFFromStream, a blank line is added. You insert RVF at the beginning of the document (because 0 is specified in the parameter of InsertRVFFromStream), so this blank line remains after the inserted content.
So, delete the first call of Format, and call Format only at the end.

PS: If you used InsertRVFFromStreamEd instead of InsertRVFFromStream, the advice would be the opposite.
This is an editing method, so it requires a formatted document before its call, so the first call of Format is required.
The last call of Format is not needed, because InsertRVFFromStreamEd reformats the changed part of the document itself.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: InsertRVFFromStream extra line at end

Post by standay »

OK, that helps, thanks Sergey!

I made a note of all this in my code.

Stan
Post Reply