Searching and Replacing in TRichView and TRichViewEdit

<< Click to display table of contents >>

Searching and Replacing in TRichView and TRichViewEdit

The following main functions for text searching are available:

function TRichView.SearchTextW(s: TRVUnicodeString;

  SrchOptions: TRVSearchOptions): Boolean;

function TRichViewEdit.SearchTextW(s: TRVUnicodeString;

  SrchOptions: TRVESearchOptions): Boolean;

These methods search for the substring s. If found:

if OnTextFound event is assigned, this event is called;

otherwise, or if DoDefault parameter of OnTextFound = True, the methods select this substring and make it visible (scroll the window to it).

A selection requires a formatted document, so, unless the result of text searching is processed inside OnTextFound, text searching methods require a formatted document as well.

The methods of TRichView start searching from the current selection (if exists) or from the first (or the last, when searching up) visible item. If rvsroFromStart is included in SrchOptions, the methods start searching from the beginning (or the end, when searching up) of the document.

The methods of TRichViewEdit start searching from the caret position.

The last stored search result position can be used instead of selection or a caret position. This position is stored by StoreSearchResult method, and is used as a starting point if rvsroFromStored/rvseoFromStored is included SrchOptions.

All the methods support the following options:

searching up or down;

case sensitive/insensitive searching;

searching for the whole words;

allowing matching in a single text item or in multiple items.

s may contain a tab character (#9). However, it makes sense only if the option for matching in multiple items is set.

 

The unit RVMisc.pas contains the functions to convert options of search dialogs:

function GetRVSearchOptions(fo: TFindOptions): TRVSearchOptions;

function GetRVESearchOptions(fo: TFindOptions):TRVESearchOptions;

It's easy to implement replacing of text in editor. SearchText selects the old substring, InsertText replaces the selected string with the new one.