Here goes the parse-and-spell-check procedure (to fully understand the code
download the entire project):
procedure TForm1.btnSpellCheckClick (Sender: TObject) ;
var
colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
j : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam)) ;
//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
{parse the memo text into words.}
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,1+itxtStart, MaxInt)) ;
if itxtLen = 0 then StopLoop := True;
Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;
if Memo.SelText = '' then Continue;
WordDoc.Range.Delete(EmptyParam,EmptyParam) ;
WordDoc.Range.Set_Text(Memo.SelText) ;
{call spell check}
colSpellErrors := WordDoc.SpellingErrors;
if colSpellErrors.Count <> 0 then begin
colSuggestions := WordApp.GetSpellingSuggestions (colSpellErrors.Item(1).Get_Text) ;
with frSpellCheck do begin
edNID.text := colSpellErrors.Item(1).Get_Text;
{fill in the list box with suggestions}
lbSuggestions.Items.Clear;
for j:= 1 to colSuggestions.Count do
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(j))) ;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(Sender) ;
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord) ;
end;
end;
end;
end;
end;
WordDoc.Disconnect;
varFalse:=False;
WordApp.Quit(varFalse) ;
Memo.SelStart := 0;
Memo.SelLength := 0;
end;