FieldLocate: Modify Field Name or Contents

Top  Previous  Next

The powerful function named FieldLocate can be used as alternative to the MergeText/OnMailMergeGetText double. It is used to locate certain fields.

 

This code will enumerate a certain group of fields and update their contents.

 

  obj := nil;

  FromStart := TRUE;

  repeat

     obj := WPRichText1.FieldLocate('A*B', '',

               FromStart,

     [wplocGlobalSearch,wplocDontMoveCursor]);

    if obj<>nil then

       obj.Embeddedtext := 'Test';

     FromStart := FALSE;

  until obj = nil;

 

An alternative method to enumerate the fields is the function FieldGetList. It will fill a list (an instance of the TWPTextObjList class) with references of fields. This list can be used to change the names of the fields and also to read or change the contents (EmbeddedText).

 

The property FieldAtCP can be used to retrieve a reference to the active field at the current cursor position. Please use this function with care since the backward search for the open object can be slow, esspecially if no field can be found. CPObj is faster, it returns any TWPTextObj directly at the current cursor position (= at the current text insertion point - do not confuse with mouse-cursor).