Example 87 : Using the TMS SpellCheck engine with TAdvStringGrid

vcl grid spellcheck

TAdvStringGrid has an easy to use interface to deal with auto-correction and/or spellchecking for text in cells, either for cells where text was loaded or set programmatically or automatically after a user edited a cell in the grid.
This easy to use interface is hooked up to the TMS SpellCheck engine via a component : TAdvStringGridSpellCheck. With this interface, it is possible to use the TMS SpellCheck engine to mark spelling errors with red underlines in the cell text or to do auto correction of cell text. To start using the TMS SpellCheck engine with TAdvStringGrid, drop a TAdvSpellCheck instance on the form. In the spell check engine, the spell check database and language(s) can be setup. Next, drop a TAdvStringGridSpellCheck component on the form and connect the TAdvSpellCheck instance to TAdvStringGridSpellChecker.SpellCheck. Finally, connect TAdvStringGrid to the grid where you need spell check via the property grid.CellChecker.

The action the spell check engine needs to perform is selected via the properties:

AdvStringGridSpellCheck.AutoCorrect: boolean;

When set to true, this will start auto correction of text entered in a cell after editing. Via the TMS SpellCheck engine, the first suggested fix for the spelling error found will replace the incorrect spelled word or, when AdvStringGridSpellCheck.ShowDialog = true, a dialog of the TMS SpellCheck engine will be shown with the cell text and will allow to correct the text word by word.

AdvStringGridSpellCheck.AutoMarkError: boolean;

When set to true, the TMS SpellCheck will be used to check the cell text and just mark misspelled words with a red underline. After this, the text can be edited again for manual correction and when the cell editings stops, the check is performed again.

Other than performing a spell check after a user has edited a cell, it is also possible to spellcheck the contents of cells in the grid as-is. Various methods are available at grid level for this:

grid.CheckGrid(DoFixed: boolean);
//Performs a spell check for all cells in the grid. When DoFixed = true, the fixed cells are also checked.
grid.CheckRow(DoFixed: boolean);
//Performs a spell check for all cells in a given row in the grid. //When DoFixed = true, the fixed cells in the row are also checked. grid.CheckCol(DoFixed: boolean; Col: integer);
//Performs a spell check for all cells in a given column in the grid. //When DoFixed = true, the fixed cells in the column are also checked. grid.CheckCell(Co, Row: integer);
//Performs a spell check for one given cell grid.CheckCells(FromCol,FromRow,ToCol,ToRow: integer);
//Performs a spell check for a given range of cells

A programmatic check also uses the properties AdvStringGridSpellCheck.AutoCorrect, AdvStringGridSpellCheck.AutoMarkError, AdvStringGridSpellCheck.ShowDialog. This means, that when AutoCorrect = true, performing grid.CheckGrid() will try to auto-correct all cell text. When ShowDialog = true, it will prompt a dialog for each cell with incorrect text and allow the user to interactively correct the text or not.

Delphi project & source files for downloading included in the main demos distribution for Delphi