[Unit] Item for saving a table of contents in RTF and DocX

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 13398
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Unit] Item for saving a table of contents in RTF and DocX

Post by Sergey Tkachenko » Mon Oct 05, 2015 8:56 am

http://www.trichview.com/support/files/rvtocitem.zip

This file contains RVTocItem.pas unit, implementing a new item type: a table of contents for exporting in RTF and DocX files.
When inserting in our editors, it looks like {TOC}.
When exporting to RTF or DocX, it looks like [Update fields to build a table of contents]. When the user right click this text in Microsoft Word and chooses "Update Field" from the context menu, Microsoft Word inserts a table of contents in its place (providing that this document has headings).

This item has property: MaxLevel, a maximal level of headings used to build TOC (counted from 1). This property can be accessed with GetExtraItemIntPropertyEx and related method as rveipcMaxLevel. For example,

Code: Select all

RichViewEdit1.SetCurrentItemExtraIntPropertyEx(rveipcMaxLevel, 4, True);
changes value of this property as an editing (undoable) operation for a TOC at the caret position.
This property also can be defined in constructor:

Code: Select all

var TOC: TRVTOCItemInfo;
begin
  TOC := TRVTOCItemInfo.CreateEx(RichViewEdit1.RVData, 3);
  RichViewEdit1.InsertItem('', TOC);
end;

Post Reply