Building and managing rich text
Managing rich text items
Along with classes that are specific for the rich text usage, the library includes also some that facilitates access to the content of the item, namely
rtCollection and and
rtCollection may be used to store, order and retrieve any kind of objects, provided they implement a unique ID string property;
rtEnumeration provides a concise way to access a
rtCollection object and consequently parse and access inner structure of rich text item (or content of
Editing, copying and deleting rich text objects may be effected on two levels. The highest level allows the manipulation through specific classes (as we saw it in above samples); the lowest level allows access to rich text records on CD-record (Composite data record) level - in the way they are stored in rich text item. Although throughout this text we assume the use of high level that does not require the knowledge of inner structure of rich text item, chapter on low level access contains information and samples for handling generic elements.
As an example of editing of rich text content, let us replace hotspot pop-up text:
Dim enum as rtEnumeration, coll as rtCollection
The method collection returns rtCollection of objects corresponding to keyword provided as an argument. Using property Collection, one may provide several keywords like a line of code:
Set coll = ctx.Collection(PARSE_GROUP_HOTSPOT or PARSE_GROUP_TABLE)
Returns a collection of all hotspots AND tables. Technically (according to the inner structure of the rich text field) Hotspots refer to a very large group of objects, including, buttons, sections, computed text and hotlinks, so after this call we may a get a large variety of objects.
Roughly equivalent way is to retrieve directly appropriate rtEnumeration; this way is available for the most popular object types.
Set enum = ctx.Hotspots ' it retrieves the rtEnumeration object that can be easily used to loop through the data set
As we are interested at the moment in pop-up text, let us loop through the returned collection and deal with the particular objects:
Dim o as Variant ' do not specify a definite type - returned collection may contain different objects
Done - every occurrence of "IBM" in pop-up texts has been replaced by "Lotus". Note that it does not apply to computed pop-ups (with formula to compute the content) or other hotspot types. For other types procedure is similar. It is described in reference section of corresponding classes. A number of samples also are available.