Live Spelling Checking in TRichView

<< Click to display table of contents >>

Live Spelling Checking in TRichView

Live spelling check marks misspelled words with special underlines (wavy line of TRVStyle.LiveSpellingColor color).

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.

Checking Words

TRichView does not have its own spelling check engine and dictionaries. You need to use third-party components.

Currently the following components are supported:

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

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

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

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

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

The following checkers were supported in older versions, discontinued (but can be restored on request):

6.EDSSpell 7.0 by OneDomain, Inc (shareware Delphi component, discontinued)

7.VSSpell 8.0 by ComponentOne LLC (shareware ActiveX, discontinued)

8.VSSpell 3.0 by Visual Components, Inc (shipped with older versions of Delphi, ActiveX)

9.LS Speller by Luzius Schneider (ISpell + MS Office (CSAPI) spell checkers, freeware)

Let me know if you are interested in supporting other spelling checkers.

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.

Single quote character is processed specially: if it's inside word, it's treated as a part of word (for example "it's" or "I'll"). If it's to the left/right, it's treated as a delimiter.

URLs are ignored, see RVIsCustomURL function.

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).

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 file)