Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Spell Checking from Delphi code using MS Word - Office Automation in Delphi

By Zarko Gajic, About.com

5 of 7

The Spell Check Project - Spell Check / Replace

GetSpellingSuggestions at Design-Time

GetSpellingSuggestions at Design-Time

The idea is to loop through the text in the Memo and parses it into space delimited words. For each word, we call MS Word to spell check it. Word's Automation model contains the SpellingErrors method that lets you check the spelling of text contained in some Range.

Range is defined to contain only the word just parsed out. The SpellingErrors method returns a collection of misspelled words. If this collection contains more that zero words we move on. A call to the GetSpellingSuggestions method, passing in the incorrectly spelled word, fills a SpellingSuggestions collection of suggested replacement words.

We pass this collection to the SpellCheck form. That is the second form in our project.

To add a new form to a project use File|New Form. Let it have the 'frSpellCheck' name. Add three TBitBtn components on this form. Two EditBox-es and one ListBox. Note the three more Labels. The "Not in dictionary" label is "connected" with the edNID edit box. The edNID simply display the misspelled word. The lbSuggestions list box will list the items in SpellingSuggestions collection. The selected spelling suggestion is placed in the edReplaceWith edit box.

The three BitButtons are used to Cancel the spell checking, Ignore the current word and to Change the misspelled word with the one in the edReplaceWith edit box. The BitBtn components ModalResult property is used when referring to what the user has clicked. The "Ignore" button has its ModalResult property set to mrIgnore, "Change" to mrOk and "Cancel" to mrAbort.

The frSpellCheck has one Public string variable called sReplacedWord. This variable returns the text in the edReplaceWith when the user presses the "Change" button.

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Advanced Delphi Techniques
  5. OLE / COM / Automation
  6. Automation
  7. The Delphi - Word Spell Check Project - Spell Check / Replace

©2009 About.com, a part of The New York Times Company.

All rights reserved.