Skip to content

Search and Replace Demo ​

Folder: Demos\SearchReplaceDemo. Project: SearchReplaceDemo.dpr.

Shows how to implement the search and replace functions with TSynEdit: the search dialog, the replace dialog, the search of the next and previous occurrence, and the confirmation of each replace.

UnitContent
frmMainThe main form with the actions Search, Search next, Search previous and Replace.
dlgSearchText, dlgReplaceTextThe dialogs, with the options of the search (case, whole word, backwards, selected text only, entire scope, regular expression).
dlgConfirmReplaceThe confirmation shown for each replace.
uSearchHighlighterClasses and routines to highlight the search term in the text (by Kiriakos Vlahos).

Points of interest ​

  • DoSearchReplaceText builds the TSynSearchOptions from the state of the dialog and calls SearchReplace of the editor.
  • The event OnReplaceText of the editor shows the confirmation dialog and answers with the TSynReplaceAction chosen by the user.
  • The event OnProcessCommand restarts the search when the user does something else in the editor, and removes the highlight of the matches when the selection is cancelled (ecCancelSelections).
  • The library contains the same dialogs, in the units SynEdit.dlgSearchText, SynEdit.dlgReplaceText and SynEdit.dlgConfirmReplace.

Released under the MPL 1.1 / GPL 2 dual license.