Stretchwickster
Programmer
Probably me being really brain-dead but is there a way of using the TRichEdit.FindText function in an upward direction. I've worked out how to detect whether the user selects Up or Down in a FindDialog and have implemented the Down direction with no problems. I just can't think how to implement the Up searching facility and I've scoured the net!
Please help!!
Clive![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
P.S. Here is my code which implements the Down direction:
Please help!!
Clive
![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
P.S. Here is my code which implements the Down direction:
Code:
procedure TForm1.FindDialog1Find(Sender: TObject);
var
FoundAt: LongInt;
StartPos, ToEnd: Integer;
SearchType: TSearchTypes;
begin
with RichEdit do
begin
if frWholeWord in FindDialog1.Options then
SearchType := SearchType + [stWholeWord]
else
SearchType := SearchType + [];
if frMatchCase in FindDialog1.Options then
SearchType := SearchType + [stMatchCase]
else
SearchType := SearchType + [];
if frDown in FindDialog1.Options then
begin
{ begin the search after the current selection if there is one }
{ otherwise, begin at the start of the text }
if SelLength <> 0 then
StartPos := SelStart + SelLength
else
StartPos := 0;
{ ToEnd is the length from StartPos to the end of the text in the rich edit control }
ToEnd := Length(Text) - StartPos;
FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, SearchType);
end
else
begin
{Up-direction code goes here}
end;
if FoundAt <> -1 then
begin
SelStart := FoundAt;
SelLength := Length(FindDialog1.FindText);
end;
end;
end;