I want to spell check words from a Richedit.Text but am having trouble
in my GetWord routine. Here is the code.
function GetWord(var p:integer):string;
{Get a word from Richedit1 starting at pos p.
Return changed p.
}
var s:string;
c:char;
i:integer;
begin
c:=midstr(Form1.Richedit1.text,p,1);
s:=''; //Beginning string
while (c in ['A'..'Z','a'..'z','-','1'..'0']) do //allowable ctrs.
begin
s:=s+c;
inc(p);
c:=midstr(Richedit1.text,p,1);
end; //while
dec(p);
GetWord:=s;
end; //GetWord
{*******************************************************}
procedure TForm1.mnuSpell2Click(Sender: TObject);
var s:string;
l,i,pos:integer;
begin
//Get a word, then check it.
pos:=0;
l:=length(Richedit1.text);
while (pos<l) do
begin
s:=GetWord(pos);
if s=uppercase(s) then break; //Ignore all caps
if ExecRegExpr('[0-9\.]+',s) then break; //Ignore all digits.
if ExecRegExpr('[A-Z][a-z]+',s) then break; //Ignore initial capped
words.
if ExecRegExpr('[a-zA-Z]*[0-9]+[A-Za-z]*',s) then break; //Ignore
words containing a digit.
janSpeller1.Spell(s);
Richedit1.Seltext:=s;
end;
end;
You will notice I want to skip certain types of words, so I have to
check for those manually since my speller doesn't. But in GetWord, c is
a char but midstr returns a string, thus I get a compile error (char
and string incompatible or something). How do I get one char at a time
from a Richedit1, while passing the current position pointer back from
GetWord to mnuSpell2Click?
Thanks.
--
Say no to fixed width tables. They look terrible!


|