BTW, I did not test this and do not think it will work on
a wrapped search value, say 'time for all'
--- Eddie Shipman <[EMAIL PROTECTED]> wrote:
> Rich, you can use the FindText function in RE to get the Selstart.
> See this little example I wrote several yrs ago.
>
> RichEdit lines are like this:
> {
> Now is the time
> for all good men
> to come to the aid
> of their country
> }
>
>
> procedure MarkThisWord(RE: TRichEdit; TheWord: String; Color: TColor; Style:
> TFontStyles);
> var
> i, CharPos, noChars: Integer;
> begin
> CharPos := 0;
> noChars := 0;
> for i := 0 to Pred(RE.Lines.Count) do
> noChars := noChars + Length(RE.Lines[i]);
> CharPos := RE.FindText(TheWord, CharPos, noChars, [stWholeWord]);
> RE.SelStart := CharPos;
> RE.SelLength := Length(TheWord);
> RE.SelAttributes.Color := Color;
> RE.SelAttributes.Style := Style;
> end;
>
> procedure MarkAllWords(RE: TRichEdit; TheWord: String; Color: TColor; Style:
> TFontStyles);
> var
> i, CharPos, CharPos2, noChars: Integer;
> begin
> CharPos := 0;
> noChars := 0;
> for i := 0 to Pred(RE.Lines.Count) do
> noChars := noChars + Length(RE.Lines[i]);
> repeat
> CharPos2 := RE.FindText(TheWord, CharPos, noChars, [stWholeWord]);
> CharPos := CharPos2+1;
> RE.SelStart := CharPos2;
> RE.SelLength := Length(TheWord);
> RE.SelAttributes.Color := Color;
> RE.SelAttributes.Style := Style;
> until charpos = 0;
> end;
>
> Syntax:
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
> MarkThisWord(RichEdit1, 'the', clRed, [fsBold]);
> MarkAllWords(RichEdit1, 'to', clTeal, [fsItalic, fsBold]);
> end;
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi