[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: 17602
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 »

Update 2018-Apr-18: the link is removed because this unit is included in the TRichView setup:
<TRichView Dir>\TRichView\Source\RVTOCItem.pas

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;
See also:
http://www.trichview.com/forums/viewtop ... 702#p34702 - overview of TOC solutions for TRichView and ScaleRichView
Post Reply