Page 1 of 1

Moved from "[Demos] Headers and Footers"

Posted: Tue Aug 27, 2019 5:34 pm
by ivanRar
I am struggling a bit with the new headers and footers and maybe you can point me in the right direction.

First issue and to keep it simple. I have two pages. I want to take the header and footer from the first page and put them on the second page. Programmatically, how would I do this?

Second issue. Is there any way to safely read/write the contents of the SubDocument items? That is to say, take the data out, update it I use dynamic insertion of values in my headers/footers, and store the results back into the original location? The LoadRVFFromStream looks intimidating.

Thanks

Re: Moved from "[Demos] Headers and Footers"

Posted: Wed Aug 28, 2019 5:37 am
by Sergey Tkachenko
1) As I understand, you want to copy the first page header to normal header.
It can be done via RVF memory stream:

Code: Select all

var
  Stream: TMemoryStream;

Stream := TMemoryStream.Create;
srve.SubDocuments[srvhftFirstPageHeader].SaveRVFToStream(Stream, False);
Stream.Position := 0;
srve.SubDocuments[srvhftNormalHeader].LoadRVFFromStream(Stream);
Stream.Free;
srve.Format;
This code works correctly if the header is not being edited. Otherwise, the current header is stored in srve.RVHeader, not in srve.SubDocuments.
So you can call this code in two cases:
- when srve is unformatted (for example, immediately after loading or generating document);
- when srve.RichViewEdit is being edited (to make sure, you can call srve.StartEditing(srvrveMain);

Re: Moved from "[Demos] Headers and Footers"

Posted: Wed Aug 28, 2019 5:41 am
by Sergey Tkachenko
2) You can find the answer in my previous reply: you can safely modify SubDocuments except for cases when headers/footers are being edited. If they are being edited, a content of the certain SubDocuments[] will be overridden by a RVHeader/RVFooter content when the editing finishes.

You can also modify content of srve.RVHeader/RVFooter, but usually it makes sense to do it using editing methods (which can be undoable by users).