我们为社区开发的 twitter 客户端的要求之一是拼写检查组件。您在应用程序中使用了哪些拼写检查组件/系统,您的使用体验如何?
8 回答
Addict Component Suite是 Delphi 最完整的一个,但它不是免费的。
但是我认为您正在为您的 twitter 实用程序寻找免费软件,我已将LS Speller用于免费项目并且与我合作得很好,它基于 ISpell,因此您可以使用更新的字典对其进行更新。
但目前还没有 D2009 更新,而且似乎还没有积极开发。
使用MS Word 内置字典的另一个选项。
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;
在博客评论中,Ken 刚刚建议使用 ISpell 词典的LS Spell 。它适用于 Delphi 5、6 和 7,所以只要它不明确使用其他字符串类型就可以正常工作。
您可以使用Aspell(Win32 版本:http ://aspell.net/win32/ )。
在您的 Delphi 项目中,您可以使用命令行管道接口aspell pipe
:
C:\Programme\Aspell\bin>aspell 管道 @(#) International Ispell 版本 3.1.20(但实际上是 Aspell 0.50.3) 你好 * 世界 * 你好 & hello 18 0:你好,Helli,hell lo,hell-lo,地狱,Heall,你好,他会,你好,Heller,Heller,你好,Jello,Jello,Halli,Holli,hallow,hollow 世界 & wourld 12 0: 世界,会,会,会,轮动,挥舞,焊接,狂野,羊毛,旋转,世界,会,词
我在我的 Delphi 应用程序中使用 TRichView 组件作为我的“文本编辑器”。
它支持许多与 Delphi 一起工作的拼写检查器。您可能想比较它支持的那些:
DevExpress VCL 也有一个拼写检查器,虽然我只玩过一点。我还拥有在软件项目中使用的 Addict。
如果您可以保证您的客户端始终安装 MS Word,我建议 MS Word 的内置拼写检查器也带有 OLE 自动化。