[Unit] Adding a table of contents

Demos, code samples. Only questions related to the existing topics are allowed here.
jonjon
Posts: 269
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon » Tue Jun 07, 2011 6:31 pm

OK Sergey, I'll wait. Thanks.

jonjon
Posts: 269
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon » Thu Sep 29, 2011 1:01 pm

Up

jonjon
Posts: 269
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon » Tue Oct 25, 2011 8:28 am

Any news on this ?

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

Post by Sergey Tkachenko » Tue Oct 25, 2011 11:48 am

Sorry, not yet. News will be in this week (good or bad - I do not know yet)

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

Post by Sergey Tkachenko » Sun Oct 30, 2011 12:11 pm

In DOC/RTF file, PAGEREF is a reference to a bookmark. When generating TOC, MS Word adds a hidden auto-maintained bookmark before each heading.
I can add checkpoints before each heading when generating TOC. However, they will not be hidden or auto-maintained, they will be like any other checkpoints. If it's ok, I'll make an example.

jonjon
Posts: 269
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon » Sun Oct 30, 2011 12:27 pm

Sergey,

Thank you for taking the time to review my question. I already have added checkpoints (bookmarks) before each heading. However the difficult part for me is to update the TOC generation so that the page number displayed is a reference to those bookmarks and not a static page number, when exported to RTF. An example would be very welcome.

John.

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

Post by Sergey Tkachenko » Sun Oct 30, 2011 4:52 pm

This unit contains code for generation TOC for RTF:
http://www.trichview.com/support/files/rvtocrtf.zip

It contains the same functions as the original version, with the same parameters.
Differences:
- new functions add checkpoints before each heading in the document;
- new functions insert RTF fields "PAGEREF" in place of page numbers.

There are 2 main ways for insertion RTF codes using TRichView:
1) using text with a style having rvteoRTFCode in Options;
2) using some control and processing OnSaveComponentToFile.

This example uses the first method. Its disadvantage: in TRichView, you can see all these codes directly in text.

The functions still require formatted document, because they calculate page numbers that will be displayed in MS Word when you load this document initially. You still need to select TOC paragraphs in Word and press F9 to update page numbers.
The code for calculating initial values of page numbers could be removed (they can be displayed initially, as, for example, '?'), it would simplify the code.

jonjon
Posts: 269
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon » Mon Oct 31, 2011 1:28 pm

This is exactly what I needed, thank you very much Sergey!

SculptureEK
Posts: 3
Joined: Wed Nov 21, 2012 3:24 pm

Small problem in TOC generation

Post by SculptureEK » Mon Oct 27, 2014 5:41 pm

The number of pages of the Table of Contents is not correctly calculated IF
- the margins of the RichView are greater than the default margins AND
- there is a TOC line which is just a bit too large to fit in 1 line AND
- because of this line we need a 2nd page for the TOC
Obviously, the RichView used to build the TOC thinks that the TOC fits in 1 page while it needs 2 pages in fact.

It works with this change in function AddTableOfContents (TRVReportHelper overload):

// building TOC in RVReportHelper2, calculating TOCPageCount
RVReportHelper2.RichView.Style := RVReportHelper.RichView.Style;
ADD-> RVReportHelper2.RichView.LeftMargin := RVReportHelper.RichView.LeftMargin;
ADD-> RVReportHelper2.RichView.RightMargin := RVReportHelper.RichView.RightMargin;
RVReportHelper2.RichView.AddNL(Title, TitleStyleNo, TitleParaNo);

Kind regards,

Hans

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

Post by Sergey Tkachenko » Tue Oct 28, 2014 1:24 pm

You are right, margins must by copied from RVReportHelper to RVReportHelper2, all 4 margins

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest