How To…Create a Table of Contents

Question

“How do I create a table of contents sorted by page at the beginning of my report?”

Solution

Use a group to separate out each topic in the table of contents.  During the first pass of the report, keep track of the current page inside the OnGroupBreak event for each group, then build the table of contents based on these values for the second pass of the report.

Download:  TableOfContents.zip

Sample Delphi code: