Delphi Spell Check

If you are looking for a free Delphi spell checking component for use in your windows applications, you cannot do much better that HunSpell. http://hunspell.sourceforge.net/

HunSpell is a free spell checker that is used by many high profile open source projects, such as OpenOffice.

It is distributed in the form of a Windows DLL that you can ship alongside your application, and also has a great number of dictionaries for various languages. http://wiki.services.openoffice.org/wiki/Dictionaries

Where To Start?

Many users downloading the Delphi code from the HunSpell page above will encounter a few problems. Firstly the code does not work with multibyte strings (Delphi 2009+), and the source code samples given depend on a Delphi project that is no longer supported to get working. There are also a couple of bugs in the code provided.

The zip file downloadable below contains all that is needed to implement spell checking in your Delphi applications.

Getting HunSpell Working:

The code in the zip file provided contains the British English dictionaries (if you need other dictionaries, check the links above), the HunSpell DLL, and a fully working non-visual component that can be installed on your component pallet, and included in your applications.

You should install the TSpellCheck component, this component has three properties:

AffFileName: The .aff file with the dictionary you wish to use.

DictFileName: The .dic file with the dictionary you wish to use.

Active: This must be set to True for the component to connect to the HunSpell DLL, and load the dictionary specified.

Creating The Spell Check Component In Code:

If the control is not setup at design time, you can setup the component in code as follows:

 Spell Checking & Suggestions:

You now have a component setup that will allow you to spell check words, and request suggestions as below:

Spell Check Dialog Box

Spell Check


Enjoy!

The zip file below also includes a demo project to get you started, play around with it a bit…

If you want to add live spelling, also checkout the Live Spell TEdit control that can be used with this component.

Download Free Delphi Spell Checker:

spell-check.zip

Live Spell Check TEdit

Delphi edit control that implements live spelling functionality. This control is not tied to a specific spell checking component or library, instead publishes an event to determine if a word is misspelled.

Live Spell Check TEdit

A Delphi TEdit Control with Live Spell Check Functionality

Using Delphi Live Spell Edit:

After downloading and installing the control into a Delphi package, you will find a new control TSpellCheckEdit on your tool pallet under the Controls section.

Adding this control to a form, you will notice a new event on the Object Inspector “OnIsMisspelled” – double click on this to assign a new procedure to this event:

You can see that this procedure has three parameters:

Sender: This will identify the control that called the event

AWord: The word that is to be checked against your dictionary.

IsMisspelled: Setting this value to True will tell the control that the word is correct, and will remove any red underline. Setting this Value to False will add red underlines to the misspelled word.

Right Click Menu Suggestions:

Although this control will not handle suggestions on the right click menu itself, it does implement a few methods and property that make this task easy.

  1. Ensure that the RightClickMoveCaret property is set to True. (this will ensure the selection changes when the user right clicks)
  2. On your TPopupMenu’s OnPopup event handler, use the GetWordAtCaret function to determine the clicked word, and add menu items containing your suggestions to the popup menu.
  3. In your MenuItems onclick event, use the ReplaceWordAtCaret function to replace the current word with the correction.

Download Live Spell Edit:

livespelledit.zip