I'm doing the following to insert a TOC field on a cover page:
and inserted a bookmark for it using:
WPRichText_Cmt.BookmarkInput( '_Toc_' + bm );WPRichText_Cmt.ActiveParagraph.ASet(WPAT_ParIsOutline,1);
where bm is some string the user can add.
and at report build time I use:
WPRichText_Rpt.CreateTableOfContents( '', '_Toc_', [wptocUseParIsOutline], nil, 'titletext', nil);
But it always puts the TOC at the end of the document, not at the paragraph where the InputMergeField was inserted.
I traced it down to a comparison in the CodeLocate routine, and it is comparing obj.Source with CmpStr2. But for some reason, obj.Source is a string '\h' and CmpStr2 is ''. If I use this instead, it works:
WPRichText_Rpt.CreateTableOfContents( '\h', '_Toc_', [wptocUseParIsOutline], nil, 'titletext', nil);
My question is, what's up with the '\h' ??
And it gets worse... if I place the WTOC input merge field further into the document, obj.Source is '\h \h \h'... perhaps a \h for every new section into the document... haven't looked at the corelation, but it would be nice to not have any \h chars!
I had to remove the 'wpCompareSource' from the CodeLocate to get it to work properly for me (i.e. not look at obj.source).
WPTools 5.20.5
Delphi 7