TCustomRichViewEdit.SearchText, SearchTextA, SearchTextW

<< Click to display table of contents >>

TCustomRichViewEdit.SearchText, SearchTextA, SearchTextW

The methods search for the substring s in the document.

function SearchText(s: String; SrchOptions: TRVESearchOptions): Boolean;

function SearchTextA(s: TRVAnsiString; SrchOptions: TRVESearchOptions): Boolean;

function SearchTextW(s: TRVUnicodeString; SrchOptions: TRVESearchOptions): Boolean;

When found, these methods select substring and move the caret to the end of selection.

If there is no selected fragment, the methods start searching from the caret position, up or down depending on SrchOptions.

If something is selected, rvseoSmartStart is used. If it is included, then:

when searching down, the search starts from the second selected character;

when searching up, the search starts from the last but one selected character;

(selected characters are counted from the top of document, the selection direction is ignored). This option allows to avoid selecting the same fragment again when changing a search direction.

If rvseoMultiItem is included, the search can match substrings of several text items. If not included, the text is searched in each text item separately. For example, if the document contains the text Hello, the substring 'Hello' can be found only if this option is included, because 'He' and 'llo' belong to different items.

unicode Unicode note:

Internally, text is stored as Unicode. SearchTextA converts s to Unicode using (Style.DefCodePage) and calls SearchTextW.

SearchText works:

like SearchTextA, in Delphi 2007 and older

like SearchTextW, in Delphi 2009 and newer

with UTF-8 string, in Lazarus


These methods can be used for search-and-replace operation as well. SearchText selects the found string, InsertText replaces it with the new one. See important note about search and replace in down-up direction in the topic about InsertText.

Note: There is incompatibility with programs written with the older version of RichView (1.0 1.1.4). Now if rvsroDown is not included in SrchOptions, the methods search upwards. In the older versions there was no rvsroDown option, and SearchText searched downwards only.

These methods must be called only when the document is formatted.

Return value:

Is the substring found?


See also:

TRichView.SearchText, -A, W;

GetRVESearchOptions global function;

Searching in RichView and RichViewEdit.