Hi All,
I've written some functions to highlight words in a group of TRichEdits,
each of which
contains distinct text. In the first TRichEdit, everything works fine. In
the second two
TRichEdits, the highlighting is off by character distances that have some
relationship
to the line number in the TRichEdit. I can't seem to find a consistent way
to set the
SelStart position for all TRichEdits.
Everything else seems to work. I can breakpoint the line after "AWord :=
Copy(TheText,I,L);"
and I always get a complete word. Only those words in the dictionary
(KeysPlusSynonyms)
return a positive index value. The only problem (which I haven't figured
out yet) is
how the RichEdit.SelStart gets set incorrectly.
Here's the code that doesn't quite work:
function IsSeparator( Ch : Char ) : Boolean;
begin
if Ch in ['a'..'z','A'..'Z','_','0'..'9']
then Result := False
else Result := True;
end;
function IsAlpha( Ch : Char ) : Boolean;
begin
if Ch in ['a'..'z','A'..'Z','_']
then Result := True
else Result := False;
end;
procedure TfmGetAllHRSectionsOfAPatentString.HighlightWord( RichEdit :
TRichEdit;
LineCount :
Integer;
I, Len :
Integer );
begin
RichEdit.SelStart := I-1-2*LineCount;
RichEdit.SelLength := Len;
RichEdit.SelAttributes.Color := clRed;
RichEdit.SelAttributes.Style := [fsBold];
{RichEdit.SelLength := 0;}
end;
procedure TfmGetAllHRSectionsOfAPatentString.HighlightKeyWords( RichEdit :
TRichEdit );
var TotalCharCount : Integer;
LastChar : Char;
NextChar : Char;
I,L : Integer;
AWord : string;
EndOfWord : Boolean;
TheText : string;
LineCount : Integer;
begin
{Highlight keywords and their synonyms}
TheText := RichEdit.Lines.Text;
TotalCharCount := Length(TheText);
NextChar := ' ';
I := 1;
LineCount := 0;
RichEdit.Lines.BeginUpdate;
while (I<(TotalCharCount-1)) do
begin
LastChar := NextChar;
NextChar := TheText[I];
if NextChar=#$D
then LineCount := LineCount+1
else if IsSeparator(LastChar)
then if IsAlpha(NextChar)
then begin
L := 1;
EndOfWord := False;
while ( ((I+L)<=TotalCharCount)
and(not EndOfWord)) do
begin
if IsSeparator(TheText[I+L])
then begin
AWord := Copy(TheText,I,L);
if
(KeysPlusSynonyms.IsBoundString(AWord)>-1)
then HighlightWord( RichEdit,
LineCount,
I,
L);
EndOfWord := True;
end;
L := L+1;
end;
NextChar := TheText[I+L-1];
I := I+L-1;
end;
I := I+1;
end;
RichEdit.Lines.EndUpdate;
end;
Does anyone see an error in calculating the SelStart position here?
Thanks for any assistance,
Rich
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi