Delphi拼写检查组件

7

我们正在为社区开发的Twitter客户端之一的要求是拥有一个拼写检查组件。您曾在应用程序中使用过哪些拼写检查组件/系统?使用它的经验如何?

8个回答

11

Addict Component Suite 是Delphi最完整的组件套件,但需要付费。

但我认为你正在寻找免费软件来完成Twitter工具,我曾经使用过LS Speller 应用于免费项目,并且符合我的需求,它基于ISpell,因此您可以使用更新的字典进行更新。

但是目前还没有D2009的更新版本,而且似乎没有积极地开发。

另一个选择是使用MS Word内置的字典


“Addictive”不是公司的名字吗?而“Addict”是产品的名字吧? - Argalatyr
在我看来,Addict非常值得。它不是免费的,但没有分销版权费。它会持续更新,可以与许多第三方备忘录/编辑组件配合使用,有很多词典,甚至可以集成到用户的自定义Word词典中。非常好的东西。 - Chris Thornton
LS Speller仅适用于Delphi 7。开发已于2015年停止。 - Gabriel

9

Windows自带拼写检查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;

使用示例:

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;
TSpellingError对象是四个值的简单封装器:
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;

2
在博客评论中,Ken建议使用使用ISpell字典的LS Spell。它适用于Delphi 5、6和7,只要它不明确使用其他字符串类型,就可以正常工作。

2

我一直在使用Addict,并且对它感到非常满意。主要是与WPTools一起用于邮件合并和发送电子邮件。


1

DevExpress VCL 也有拼写检查器,虽然我只是稍微玩了一下。我还拥有 Addict,我在软件项目中使用它。


1

您可以使用 Aspell(Win32 版本:http://aspell.net/win32/)。

在您的 Delphi 项目中,您可以使用命令行管道接口:aspell pipe

C:\Programme\Aspell\bin>aspell pipe
@(#) 国际 Ispell 版本 3.1.20(但实际上是 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

1

我在我的Delphi应用程序中使用TRichView组件作为我的“文本编辑器”。

它支持许多与Delphi一起工作的拼写检查器。您可能希望比较它支持的这些拼写检查器:

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


0
如果您可以保证您的客户始终安装了 MS Word,我建议使用 MS Word 内置的拼写检查器,并结合 OLE 自动化技术。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接