TCustomRichView.OnReadField

<< Click to display table of contents >>

TCustomRichView.OnReadField

Occurs when reading fields from RTF or DocX file.

type // defined in RVStyle unit

 

  TRVRTFFieldResultAction =
    (rvrtffraInsert, rvrtffraCollectText);
 
  TRVFieldResultData = record
    FieldResultAction: TRVRTFFieldResultAction;
    Item: TObject;
    Text: TRVUnicodeString;
    Tag: TRVTag;
    StyleNo: Integer;
  end;
 
  TRVFieldContext = record
    FirstTime: Boolean;
    ParaNo: Integer;
    FieldResultText: TRVUnicodeString;
  end;

 
type
  TRVReadFieldEvent = procedure (
    Sender: TCustomRichView;
    const FieldCode: TRVUnicodeString; 
    Context: TRVFieldContext;
    DocFormat: TRVLoadFormat; 
    out FieldResult: TRVFieldResultData;
    var DoDefault: Boolean) of object;
 
property OnReadField: TRVReadFieldEvent;

(introduced in version 22)

This event occurs when reading fields from RTF or DocX files. It occurs only for fields that are not processed by TRichView itself.

Input parameters:

FieldCode – field code, including RTF/DocX field name and parameters

DocFormat – format of loaded document, rvlfRTF or rvlfDocX

Context – additional information describing the current state of RTF/DocX reading

DoDefault = True

 

Output parameters:

DoDefault if False, TRichView should perform the action described in FieldResult; if True, TRichView should perform default processing (i.e., reading the field result from RTF/DocX, and inserting it as normal content).

FieldResult describes the action that must be performed by TRichView in the place of this field; used only if DoDefault = False.

Option 1: inserting an item

If you assign FieldResult.FieldResultAction = rvrtffraInsert, the content described in FieldResult must be inserted in TRichView.

If FieldResult.Item <> nil, it must be an object of class inherited from TCustomRVItemInfo. This item will be inserted in TRichView document, FieldResult.Text will be used as an item text. If this item has an associated text style (for example, TRVLabelItemInfo has TextStyleNo property), you can assign rvsDefStyle to the index of text style; TRichView will replace this value to the index representing the current text attributes in RTF/DocX.

Option 2: inserting text

If you assign FieldResult.FieldResultAction = rvrtffraInsert, the content described in FieldResult must be inserted in TRichView.

If FieldResult.Item = nil, text FieldResult.Text will be inserted. If FieldResult.StyleNo >=0, it defines a text style of this text (index in Style.TextStyles collection). If FieldResult.StyleNo < 0 (or is equal to rvsDefStyle), the current RTF/DocX text attributes are used. FieldResult.Text may be multiline, but cannot contain tab (#9) characters. If FieldResult.Tag <> '', this tag is assigned to this text.

Option 3: collecting text

If you assign FieldResult.FieldResultAction = rvrtffraCollectText, nothing will be inserted after calling this event. Instead, the component will read the field result, collecting text from it. The event will be called for the second time for the same field, with Context.FirstTime = False, and the collected text in Context.FieldResultText.

Additional information in Context

Fields of Context parameter:

FirstTime = True if the event is called for the first time for the given field. False if it is called after collecting text from the field result.

FieldResultText – collected text, valid only if FirstTime = False.

ParaNo – index of paragraph style (in Style.ParaStyles collection) representing the current paragraph attributes in RTF/DocX file. While paragraph index will be assigned to the inserted content by TRichView, this property can be useful if you assign your own text style (to FieldResult.StyleNo; or a text style associated with FieldResult.Item). Knowing ParaNo, if StyleTemplates are used, you can assign a text style with the proper value of ParaStyleTemplateId.