Question

One of the requirements for the twitter client we are developing for the community is a spellcheck component. What are some of the spellcheck components/systems you have used in applications and what was your experience using it?

Was it helpful?

Solution

Windows comes with a spell checker API (Windows 8).

TWindow8SpellChecker = class(TCustomSpellChecker)
private
    FSpellChecker: ISpellChecker;
public
    constructor Create(LanguageTag: UnicodeString='en-US');

    procedure Check(const text: UnicodeString; const Errors: TList); override; //gives a list of TSpellingError objects
    function Suggest(const word: UnicodeString; const Suggestions: TStrings): Boolean; override;
end;

With implementation:

constructor TWindow8SpellChecker.Create(LanguageTag: UnicodeString='en-US');
var
    factory: ISpellCheckerFactory;
begin
    inherited Create;

    factory := CoSpellCheckerFactory.Create;
    OleCheck(factory.CreateSpellChecker(LanguageTag, {out}FSpellChecker));
end;

procedure TWindow8SpellChecker.Check(const text: UnicodeString; const Errors: TList);
var
    enumErrors: IEnumSpellingError;
    error: ISpellingError;
    spellingError: TSpellingError;
begin
    if text = '' then
        Exit;

    OleCheck(FSpellChecker.Check(text, {out}enumErrors));

    while (enumErrors.Next({out}error) = S_OK) do
    begin
        spellingError := TSpellingError.Create(
                error.StartIndex,
                error.Length,
                error.CorrectiveAction,
                error.Replacement);
        Errors.Add(spellingError);
    end;
end;

function TWindow8SpellChecker.Suggest(const word: UnicodeString; const Suggestions: TStrings): Boolean;
var
    hr: HRESULT;
    enumSuggestions: IEnumString;
    ws: PWideChar;
    fetched: LongInt;
begin
    if (word = '') then
    begin
        Result := False;
        Exit;
    end;

    hr := FSpellChecker.Suggest(word, {out}enumSuggestions);
    OleCheck(hr);

    Result := (hr = S_OK); //returns S_FALSE if the word is spelled correctly

    ws := '';
    while enumSuggestions.Next(1, {out}ws, {out}@fetched) = S_OK do
    begin
        if fetched < 1 then
            Continue;

        Suggestions.Add(ws);

        CoTaskMemFree(ws);
    end;
end;

The TSpellingError object is a trivial wrapper around four values:

TSpellingError = class(TObject)
protected
    FStartIndex: ULONG;
    FLength: ULONG;
    FCorrectiveAction: CORRECTIVE_ACTION;
    FReplacement: UnicodeString;
public
    constructor Create(StartIndex, Length: ULONG; CorrectiveAction: CORRECTIVE_ACTION; Replacement: UnicodeString);
    property StartIndex: ULONG read FStartIndex;
    property Length: ULONG read FLength;
    property CorrectiveAction: CORRECTIVE_ACTION read FCorrectiveAction;
    property Replacement: UnicodeString read FReplacement;
end;

OTHER TIPS

Addict Component Suite is the most complete one for Delphi, but it's not free.

But I think you are looking for freeware for your twitter utility, I have used LS Speller for free project and worked fine with me, it's based on ISpell, so you can update it with newer dictories.

But there's no D2009 update yet, and seems it's not actively developed.

Another option to use the MS Word built in dictionary.

In the blog comments Ken just suggested LS Spell which uses the ISpell dictionaries. It is for Delphi 5, 6 and 7, so as long as it doesn't make explicit use of other string types might work fine.

I've been using Addict and have been pretty happy with it. I've used it mainly in conjunction with WPTools for mail merge & emailing.

You can use Aspell (Win32 version: http://aspell.net/win32/).

In your Delphi project you could use the command line pipe interface: aspell pipe:

C:\Programme\Aspell\bin>aspell pipe
@(#) International Ispell Version 3.1.20 (but really Aspell 0.50.3)

hello
*

world
*

helllo
& helllo 18 0: hello, Helli, hell lo, hell-lo, hell, Heall, hallo, he'll, hullo,  Heller, heller, hellos, Jello, jello, Halli, Holli, hallow, hollow

wourld
& wourld 12 0: world, would, wold, whorled, wield, weld, wild, wooled, whirled, worlds, woulds, word

I use the TRichView component as my "text editor" in my Delphi application.

It supports many spellcheckers that work with Delphi. You may want to compare the ones that it supports:

http://www.trichview.com/features/spellcheck.html

DevExpress VCL also has a spell checker, though I have only played with a bit. I also own Addict which I use in software projects.

If you can guarantee that your client always has MS Word installed, I'd suggest MS Word's built in spellchecker too with OLE automation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top