Function TWPCustomRtfEdit.FieldLocate(FieldName:string; fieldcommand:string; FromStart:Boolean; Modes:TWPFieldLocateOptions) : TWPTextObj

Unit: WPCTRMemo
Class: WPCTRMemo.TWPCustomRtfEdit

Parameters

Returns

The type of the result value is TWPTextObj.

Description

This functions works a bit similar to but has been provided for a completely different task. While MoveToField is used to locate fields in edit mode (form fields usually) FieldLocate can be used to replace the MergeText function. It makes it possible to one after the other locate each field in text for update or content retrieval.

FieldLocate can optionally ignore Edit fields. It further more can also compare the 'Source' property with the parameter fieldcommand. The name and the command are not compared if an empty string is passed for the respective parameter.
Both string parameters may also contrain one wildcard chracter "*".
The function will, unlike MoveToField, move the cursor outside of field objects even if the form completion mode is active.
Modes:
wplocDontMoveCursor: Move the cursor to the found position - the screen is never updated. ShowCursor must be called.
wplocGlobalSearch: Search in all texts wplocIgnoreEditFieldsIgnore Editfields
If wplocDontMoveCursor =true the function will use its own paragraph reference to remember the last position for the next call with FromStart=false. This can cause an error in case that paragraph has been deleted between calls to FieldLocate.

This code replaces the contents of a certain group of fields ("AxxxB") with the value 'Test'. 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;