Page 1 of 1

InsertRVFFromStream extra line at end

Posted: Wed Sep 13, 2023 2:24 pm
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

Re: InsertRVFFromStream extra line at end

Posted: Thu Nov 02, 2023 1:48 pm
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.

Re: InsertRVFFromStream extra line at end

Posted: Thu Nov 02, 2023 2:09 pm
by standay
OK, that helps, thanks Sergey!

I made a note of all this in my code.

Stan