Building RichView Document
|Top Previous Next|
Creating a New Document
You can build document by:
3.reformatting and redrawing RichView.
Therefore, a general structure of document generation procedure is:
Note: all methods introduced in RichView (except for the formatting methods) do not reformat document, do not redraw RichView and do not call OnChange event (RichView does not have OnChange event, it is introduced in TRichViewEdit) ( viewer-style methods)
A group of methods for adding items is the largest group of methods (and contains a large number of methods for backward compatibility).
Appending Text Items
Important: Do not pass string with cr, lf or cr+lf, tab and page break characters in the functions below, except for AddText*** methods!
Some text items can be hypertext. Hypertext items are added by the same methods as regular text items.
Methods working with String parameter
These methods add text specified in a String parameter. This parameter is Unicode for Delphi/C++Builder 2009, and ANSI for the older versions of Delphi/C++Builder.
▪AddNL(S, StyleNo, ParaNo) – adds one item with text S; StyleNo is an index in the collection of text styles (RichView.Style.TextStyles); ParaNo is an index in the collection of paragraph styles (RichView.Style.ParaStyles) (if this item will start a new paragraph) or -1 (if this item will continue the paragraph).
▪Add(S, StyleNo) – equivalent to AddNL(S, StyleNo, -1).
▪AddTextNL(s, StyleNo, FirstParaNo, OtherParaNo) – adds one or more text items; the first item is added with FirstParaNo paragraph style, and other items are added as new paragraphs with OtherParaNo paragraph style; items are separated by cr, lf or cr+lf characters in s; s can contain page break and tab characters.
▪AddFmt(FormatStr, Args, StyleNo, ParaNo) adds Format(FormatStr, Args) string, where Format is a function from SysUtils unit.
Methods working with ANSI/Unicode explicitly
Notes for former users of freeware version:
In older versions of RichView you was not able to add empty strings, which are useful as empty paragraphs. Now there is no such limitation.
In older versions, there was no special processing of tab characters: they were displayed as special characters. Now Add*** methods replace tab characters with spaces or insert them as tabulators (RichView.Style.SpacesInTab space characters per one tab; changing SpacesInTab will not change already created document).
You can add picture of any Delphi format – TBitmap, TIcon, TMetafile, TJpegImage or third party graphic format.
You should create a picture and TRichView will destroy it itself when necessary (for example, when you call RichView.Clear).
▪AddPictureEx(Name, gr, ParaNo, VAlign)
▪Obsolete method: AddPicture.
Appending Hot Images
Appending Delphi Controls
You can add any Delphi control in RichView, and it will work as usual. You should create the control and RichView will destroy it itself when necessary (for example, when you call RichView.Clear). The methods for adding controls assign RichView to control.Parent.
▪Obsolete method: AddControl.
This version of TRichView, like old ones, uses Tag properties of inserted components for internal needs (do not confuse with RichView items tags).
Appending Bullets – Images from ImageLists
▪AddBulletEx (Name, ImageIndex, ImageList, ParaNo)
▪Obsolete method: AddBullet.
Appending Hotspots – Hypertext Images from ImageLists
Hotspots are just like bullets, but can have two images ("normal" and "hot") and can be used as hypertext link.
▪AddHotspotEx(Name, ImageIndex, HotImageIndex, ImageList, ParaNo) – similar to AddBulletEx
▪Obsolete method: AddHotspot.
Appending Breaks – Horizontal Lines
Adding Paragraphs' Bullets and Numbering (list markers)
List markers can be added using SetListMarkerInfo method. Unlike the methods above, this method can insert list markers not only to the end of document, but set them for existing paragraphs.
Adding Other Items
Tables, labels, numbered sequences, endnotes, footnotes, references to parent footnotes and endnotes, custom item types do not have special methods for adding them to documents. All of them are added by AddItem method.
Checkpoints are not items of RichView, but methods for adding checkpoints are similar to methods for adding items. The main methods for appending checkpoints are AddNamedCheckpointEx, AddNamedCheckpointExTag. See "checkpoints".
Adding Page Breaks
Page break is an item property ("this item starts a new page" flag). Only items that start a new paragraph can start a new page.
var ItemNo: Integer;
MyRichView.AddNLATag('First page', 0, 0, '');
ItemNo := MyRichView.ItemCount;
MyRichView.AddNLATag('Second page', 0, 0, '');
MyRichView.PageBreaksBeforeItems[ItemNo] := True;
Appending and Inserting RVF
You can append RVF data by the methods:
▪function InsertRVFFromStream(Stream: TStream; Index: Integer):Boolean;
This method can insert RVF. The first item of RVF will have the specified Index. For example, if you want to append items from RVF, write:
InsertRVFFromStream is the only method of RichView (not RichViewEdit) for inserting items.
▪function AppendRVFFromStream(Stream: TStream; ParaNo: Integer):Boolean;
This method is similar to InsertRVFFromStream (if it used for appending RVF), but it ignores paragraph style of the first item in RVF and uses ParaNo instead of it. ParaNo is an index in the collection of paragraph styles (RichView.Style.ParaStyles) (if item will start a paragraph) or -1 (if the item will continue paragraph).
Appending Content of Another RichView
▪procedure AppendFrom(Source: TCustomRichView);
This is the most efficient method to copy contents of one RichView to another one. But items of some types (including Inserted controls and tables) are not copied with this method (just ignored).
Methods for loading (Load***) belong to this group of methods as well.
There is an important change in version 1.2: you can add items from new line without starting a new paragraph. There are no new methods for generating documents (it is added in v1.3: AddTextNLW), but there is a method that affects their behavior: TRichView.SetAddParagraphMode.
TRichView © trichview.com