BpcMSSpellCheck
Late Binding MS Word Based Spell Checker for Normal and Rich Text
Language: Delphi 7 - 2007
// =============================================================================
// MS Word COM Interface to Spell Check and Synonyms
// Original Version: Mike Heydon Dec 2000
// mheydon@eoh.co.za
// Updated and Expanded: JGBishop 2005,2007,2008
// =============================================================================
uses
Windows,
SysUtils,
Classes,
ComObj,
Dialogs,
Forms,
StdCtrls,
Controls,
Buttons,
Graphics,
ComCtrls;
type
// Event definitions
TbpcMSSpellCheckBeforeCorrection = procedure(Sender : TObject;
MispeltWord : string;
Suggestions : TStrings) of object;
TbpcMSSpellCheckAboutToChange = procedure(Sender : TObject;
FocusControl : TObject;
MispeltWord : string; CorrectedWord : string;
var AllowChange : boolean; Var CancelChanges : boolean) of object;
TbpcMSSpellCheckAfterCorrection = procedure(Sender : TObject;
MispeltWord : string;
CorrectedWord : string) of object;
TbpcMSSpellCheckOnCorrection = procedure(Sender : TObject;
var WordToCorrect : string) of object;
TbpcMSSpellCheckOnHideSelection = procedure(sender : TObject; editcontrol : TObject; OnOrOff : boolean) of object;
TbpcMSSpellCheckOnReadHideSelection = procedure(sender : TObject; editcontrol : TObject; var OnOrOff : boolean) of object;
TbpcMSSpellCheckOnReadText = procedure(sender : TObject; editcontrol : TObject; var StrBuf : string) of object;
// Property types
TbpcMSSpellCheckReplacement = (repDefault,repUser);
TbpcMSSpellCheckLetters = set of char;
TbpcMSSpellCheckLanguage = (wdLanguageNone,wdNoProofing,wdDanish,wdGerman,
wdSwissGerman,wdEnglishAUS,wdEnglishUK,wdEnglishUS,
wdEnglishCanadian,wdEnglishNewZealand,
wdEnglishSouthAfrica,wdSpanish,wdFrench,
wdFrenchCanadian,wdItalian,wdDutch,wdNorwegianBokmol,
wdNorwegianNynorsk,wdBrazilianPortuguese,
wdPortuguese,wdFinnish,wdSwedish,wdCatalan,wdGreek,
wdTurkish,wdRussian,wdCzech,wdHungarian,wdPolish,
wdSlovenian,wdBasque,wdMalaysian,wdJapanese,wdKorean,
wdSimplifiedChinese,wdTraditionalChinese,
wdSwissFrench,wdSesotho,wdTsonga,wdTswana,wdVenda,
wdXhosa,wdZulu,wdAfrikaans,wdArabic,wdHebrew,
wdSlovak,wdFarsi,wdRomanian,wdCroatian,wdUkrainian,
wdByelorussian,wdEstonian,wdLatvian,wdMacedonian,
wdSerbianLatin,wdSerbianCyrillic,wdIcelandic,
wdBelgianFrench,wdBelgianDutch,wdBulgarian,
wdMexicanSpanish,wdSpanishModernSort,wdSwissItalian);
// Main TbpcMSSpellCheck Class
TbpcMSSpellCheck = class(TComponent)
private
FLetterChars : TbpcMSSpellCheckLetters;
FFont : TFont;
FColor : TColor;
FReplaceDialog : TbpcMSSpellCheckReplacement;
FCompletedMessage,
FActive : boolean;
FLanguage : TbpcMSSpellCheckLanguage;
FForm : TForm;
FEbox : TEdit;
FLbox : TListBox;
FCancelBtn,
FChangeBtn : TBitBtn;
FBeforeCorrection : TbpcMSSpellCheckBeforeCorrection;
FAfterCorrection : TbpcMSSpellCheckAfterCorrection;
FOnCorrection : TbpcMSSpellCheckOnCorrection;
FOnHideSelection : TbpcMSSpellCheckOnHideSelection;
FOnReadHideSelection : TbpcMSSpellCheckOnReadHideSelection;
FOnReadTextBuf : TbpcMSSpellCheckOnReadText;
FAboutToChange : TbpcMSSpellCheckAboutToChange;
FRPCErrorCount : integer;
FUseExistingInstance : boolean;
procedure SetFFont(NewValue : TFont);
protected
procedure MakeForm;
procedure CloseForm;
procedure SuggestedClick(Sender : TObject);
public
MsWordApp,
MsSuggestions : OleVariant;
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
function GetSynonyms(StrWord : string; Synonyms : TStrings) : boolean;
function CheckWordSpelling(StrWord : string;
Suggestions : TStrings) : boolean;
procedure CheckTextSpelling(var StrText : string);
procedure CheckRichTextSpelling(RichEdit : TCustomRichEdit; bLineAdjust : boolean=False);
procedure CheckMemoTextSpelling(Memo : TCustomMemo);
procedure CheckEditTextSpelling(Memo : TCustomEdit);
Function Connect : Boolean;
Function DisConnect : Boolean;
property Active : boolean read FActive;
property LetterChars : TbpcMSSpellCheckletters read FLetterChars write FLetterChars;
published
property Language : TbpcMSSpellCheckLanguage read FLanguage
write FLanguage;
property CompletedMessage : boolean read FCompletedMessage
write FCompletedMessage;
property Color : TColor read FColor write FColor;
property Font : TFont read FFont write SetFFont;
property BeforeCorrection : TbpcMSSpellCheckBeforeCorrection
read FBeforeCorrection
write FBeforeCorrection;
property AboutToChange : TbpcMSSpellCheckAboutToChange
read FAboutToChange
write FAboutToChange;
property AfterCorrection : TbpcMSSpellCheckAfterCorrection
read FAfterCorrection
write FAfterCorrection;
property OnCorrection : TbpcMSSpellCheckOnCorrection
read FOnCorrection
write FOnCorrection;
property OnHideSelection : TbpcMSSpellCheckOnHideSelection
read FOnHideSelection
write FOnHideSelection;
property OnReadHideSelection : TbpcMSSpellCheckOnReadHideSelection
read FOnReadHideSelection
write FOnReadHideSelection;
property OnReadTextBuf : TbpcMSSpellCheckOnReadText
read FOnReadTextBuf
write FOnReadTextBuf;
property ReplaceDialog : TbpcMSSpellCheckReplacement
read FReplaceDialog
write FReplaceDialog;
property UseExistingInstance : boolean read FUseExistingInstance
write FUseExistingInstance;
end;