Live Spelling Checking in TRichView

<< Click to display table of contents >>

Live Spelling Checking in TRichView

A live spelling check marks misspelled words with special underlines:

[VCL and LCL] wavy line of TRVStyle.LiveSpellingColor color

[FMX] dashed line of TRVStyle.LiveSpellingColor color

A spelling check is executed in background thread.

Starting and finishing spelling check

In TRichView:

Spelling check is started by calling StartLiveSpelling method.

In TRichViewEdit:

Spelling check is started:

by calling StartLiveSpelling method or

when user modifies document or when any editing-style method is called (if LiveSpellingMode=rvlspOnChange)

Spelling check is stopped by ClearLiveSpellingResults method. Clear also stops checking.

Using spelling checking components

rvspellchecker The recommended component for spelling checking is TRVSpellChecker.

Additionally, the following third-party components are supported:

1.Addict 3 and 4 by Addictive Software (shareware Delphi component, discontinued)

2.ExpressSpellChecker by Developer Express Inc. (shareware Delphi component)

3.HunSpell (opensource C++ library under GPL/LGPL/MPL tri-license)

4.ASpell by Kevin Atkinson (opensource DLL, license: LGPL)

5.Polar SpellChecker Component by by Polar (shareware ActiveX)

The live spelling thread calls OnSpellingCheck event for each word in the document.

“Word” is defined as a run of characters between delimiters. Additionally, '&' is treated as a delimiter. Apostrophes are processed specially, see RichViewApostropheInWord global variable.

URLs are ignored, see RVIsCustomURL function.

[FMX] Using platform service

In FireMonkey, TRichViewEdit can use a spelling check service (IFMXSpellCheckerService) provided by some platforms (for example, macOS).

To enable using a platform service, assign CheckSpelling = True.

In this case, it's not necessary to process OnSpellingCheck event, words are checked using a platform service. However, if the event is assigned, it is used instead of a service.

Making corrections

Call LiveSpellingValidateWord if user added word in a custom dictionary or ignore list.

Call GetCurrentMisspelling to get or to correct the current misspelled word. For example, you can use this method to implement popup menu:

1.when context menu is about to be shown, use GetCurrentMisspelling to get misspelled word in the caret position and to generate suggestions;

2.when the user has chosen a suggestion, use GetCurrentMisspelling again to select the misspelled word and use InsertText to insert replacement.

Alternatively, misspelled word can be selected on the step 1 (before displaying popup menu).

Popup menu

VCL and LCL version of TRichView does not provide special methods for adding items for correction of misspelled word to a popup menu. However, they are implemented in RichViewActions, in TRVAPopupMenu component, and in the components for TRichView+DevExpress integration.

In FireMonkey, if PopupMenu property is not assigned, TRichViewEdit displays a special default popup menu. Items for correction of misspelled words are added in this default menu automatically. If you use a third-party spelling checker instead of a platform service, OnGetSpellingSuggestions event is used to add these items. Note that only items with suggestions are added (“Ignore”, “Ignore All”, “Add to Dictionary” items are not created automatically).

Spelling Check and Document Editing

When calling a editing-style method, you do not need to worry about live spelling, everything is processed automatically (the method pauses the live spelling thread, makes changes, then resumes the live spelling thread from the proper position).

However, when calling any viewer-style method for modifying a document, you must be sure that live spelling is not running. If you call Clear and then create a new document, everything is OK, because Clear stops live spelling check. But if you make changes in existing document, call ClearLiveSpellingResults before these changes.

Memory Usage

Live spelling support adds 8 extra bytes per each item. If you do not use it, you can compile your application with RVDONOTUSELIVESPELL compiler define (see RV_Defs.inc file)