BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Spell check

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Bob Berry
Guest





PostPosted: Fri Sep 02, 2005 11:17 pm    Post subject: Spell check Reply with quote



I have a requirement to use the Word spell checker in a DB application. I
have found several references to spell check in this newsgroup, but I am
still in the dark as to how to proceed. Can someone point me in the right
direction? For this post, let's assume I have text in a RichEdit control
that I want to check. Thanks.


Back to top
Rudy
Guest





PostPosted: Mon Sep 05, 2005 7:58 pm    Post subject: Re: Spell check Reply with quote



Hey Buddy,

I have used a spell checker in my app. There is a procedure that does the
spell checking and a form that is displayed with the suggestions etcs. The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy


Back to top
Bob Berry
Guest





PostPosted: Wed Sep 07, 2005 7:33 pm    Post subject: Re: Spell check Reply with quote



Rudy,

Thanks for the tip. I found that same example in about.com and was in the
process of adapting it. I will use your code instead.

Bob

"Rudy" <rhentzen (AT) hotmail (DOT) com> wrote

Quote:
Hey Buddy,

I have used a spell checker in my app. There is a procedure that does the
spell checking and a form that is displayed with the suggestions etcs.
The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy





Back to top
Bob Berry
Guest





PostPosted: Fri Sep 09, 2005 5:27 pm    Post subject: Re: Spell check Reply with quote

Rudy,

I got it working in XP with a few mods, but in Win2K when I try to connect
to the WordApp I get "interface not supported". Have you tried this with
Win2K with any success?

Bob

"Rudy" <rhentzen (AT) hotmail (DOT) com> wrote

Quote:
Hey Buddy,

I have used a spell checker in my app. There is a procedure that does the
spell checking and a form that is displayed with the suggestions etcs.
The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy





Back to top
George Birbilis
Guest





PostPosted: Sat Sep 10, 2005 3:35 pm    Post subject: Re: Spell check Reply with quote

which office? is it office2003, officeXP (2002) or office2000 or office97?

--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
QuickTime, Delphi, ActiveX, .NET, IPC
--------------
"Bob Berry" <callbob (AT) paymentsinhand (DOT) com> wrote

Quote:
Rudy,

I got it working in XP with a few mods, but in Win2K when I try to connect
to the WordApp I get "interface not supported". Have you tried this with
Win2K with any success?

Bob

"Rudy" <rhentzen (AT) hotmail (DOT) com> wrote in message
news:431ca329$1 (AT) newsgroups (DOT) borland.com...
Hey Buddy,

I have used a spell checker in my app. There is a procedure that does
the
spell checking and a form that is displayed with the suggestions etcs.
The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy







Back to top
Bob Berry
Guest





PostPosted: Mon Sep 12, 2005 2:13 am    Post subject: Re: Spell check Reply with quote

Office 2K

"George Birbilis" <birbilis (AT) kagi (DOT) com> wrote

Quote:
which office? is it office2003, officeXP (2002) or office2000 or office97?

--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
QuickTime, Delphi, ActiveX, .NET, IPC
--------------
"Bob Berry" <callbob (AT) paymentsinhand (DOT) com> wrote in message
news:4321c5ae (AT) newsgroups (DOT) borland.com...
Rudy,

I got it working in XP with a few mods, but in Win2K when I try to
connect
to the WordApp I get "interface not supported". Have you tried this
with
Win2K with any success?

Bob

"Rudy" <rhentzen (AT) hotmail (DOT) com> wrote in message
news:431ca329$1 (AT) newsgroups (DOT) borland.com...
Hey Buddy,

I have used a spell checker in my app. There is a procedure that does
the
spell checking and a form that is displayed with the suggestions etcs.
The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy









Back to top
Hans van Leth
Guest





PostPosted: Tue Oct 04, 2005 6:59 pm    Post subject: Re: Spell check Reply with quote

Hi,

I am using the same code as Rudy to perform spell checking in my app. This
works fine with Word 2000 and Word XP.

However, in Word 2003, this code doesn't work (no SpellingErrors are ever
returned, no errormessages displayed nor exeptions raised).

Any idea why this is so and how it can be solved?

Thanks!

Hans van Leth,
Netherlands.


"Bob Berry" <callbob (AT) paymentsinhand (DOT) com> schreef in bericht
news:4324e401$1 (AT) newsgroups (DOT) borland.com...
Quote:
Office 2K

"George Birbilis" <birbilis (AT) kagi (DOT) com> wrote in message
news:4322fcf0 (AT) newsgroups (DOT) borland.com...
which office? is it office2003, officeXP (2002) or office2000 or
office97?

--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
QuickTime, Delphi, ActiveX, .NET, IPC
--------------
"Bob Berry" <callbob (AT) paymentsinhand (DOT) com> wrote in message
news:4321c5ae (AT) newsgroups (DOT) borland.com...
Rudy,

I got it working in XP with a few mods, but in Win2K when I try to
connect
to the WordApp I get "interface not supported". Have you tried this
with
Win2K with any success?

Bob

"Rudy" <rhentzen (AT) hotmail (DOT) com> wrote in message
news:431ca329$1 (AT) newsgroups (DOT) borland.com...
Hey Buddy,

I have used a spell checker in my app. There is a procedure that does
the
spell checking and a form that is displayed with the suggestions etcs.
The
code (after some tweaking) came from
http://delphi.about.com/od/kbcontrolole/l/aa032701a.htm

The procedure I use is below

procedure TInventoryForm.SpellCheck(Memo : TMemo);
var colSpellErrors : ProofreadingErrors;
colSuggestions : SpellingSuggestions;
i : Integer;
StopLoop : Boolean;
itxtLen, itxtStart : Integer;
varFalse : OleVariant;
begin
WordApp.Connect;
WordDoc.ConnectTo(WordApp.Documents.Add(EmptyParam, EmptyParam,
EmptyParam, EmptyParam));

//main loop
StopLoop:=False;
itxtStart:=0;
Memo.SelStart:=0;
itxtlen:=0;
while not StopLoop do begin
itxtStart := itxtLen + itxtStart;
itxtLen := Pos(' ', Copy(Memo.Text,itxtStart+1,MaxInt));
if itxtLen = 0 then
itxtLen := Length(Memo.Text) - itxtStart + 1;
if itxtLen = 0 then StopLoop := True;

Memo.SelStart := itxtStart;
Memo.SelLength := -1 + itxtLen;

if Memo.SelText = '' then Continue;

Caption:=Memo.SelText;

WordDoc.Range.Delete(EmptyParam,EmptyParam);
WordDoc.Range.Set_Text(Memo.SelText);
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;
lbSuggestions.Items.Clear;
for i:= 1 to colSuggestions.Count do begin
lbSuggestions.Items.Add(VarToStr(colSuggestions.Item(i)));
end;
lbSuggestions.ItemIndex := 0;
lbSuggestionsClick(nil);
ShowModal;
case frSpellCheck.ModalResult of
mrAbort: Break;
mrIgnore: Continue;
mrOK:
if sReplacedWord <> '' then begin
Memo.SelText := sReplacedWord;
itxtLen := Length(sReplacedWord);
end;
end; //case
end; //with frSpellCheck
end; //if colSpellErrors.Count <> 0
end; //main while loop

Memo.SelStart := 0;
Memo.SelLength := 0;
varFalse := False;
WordDoc.Disconnect;

end;

And the form that is shown (taken from the aforementioned site is)

unit SpellCheckForm;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, Buttons;

type
TfrSpellCheck = class(TForm)
lbSuggestions: TListBox;
Label1: TLabel;
edNID: TEdit;
Label2: TLabel;
edReplaceWith: TEdit;
btnChange: TBitBtn;
btnIgnore: TBitBtn;
Label3: TLabel;
btnCancel: TBitBtn;
procedure lbSuggestionsClick(Sender: TObject);
procedure btnChangeClick(Sender: TObject);
procedure btnIgnoreClick(Sender: TObject);
private
{ Private declarations }
public
sReplacedWord : string;
{ Public declarations }
end;

var
frSpellCheck: TfrSpellCheck;

implementation

{$R *.DFM}

procedure TfrSpellCheck.lbSuggestionsClick(Sender: TObject);
begin
if lbSuggestions.ItemIndex <> -1 then
edReplaceWith.Text := lbSuggestions.Items[lbSuggestions.ItemIndex];

end;

procedure TfrSpellCheck.btnChangeClick(Sender: TObject);
begin
sReplacedWord := edReplaceWith.Text;
//Close;
end;

procedure TfrSpellCheck.btnIgnoreClick(Sender: TObject);
begin
sReplacedWord := '';
Close;
end;

end.

Hope this helps

Rudy











Back to top
George Birbilis
Guest





PostPosted: Tue Oct 04, 2005 9:49 pm    Post subject: Re: Spell check Reply with quote

Quote:
Any idea why this is so and how it can be solved?

some kind of copyright protection by MS? not sure


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
QuickTime, Delphi, ActiveX, .NET, IPC
--------------



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.