Поиск текста в компоненте RichEdit - Delphi
function SearchForText_AndSelect(RichEdit: TRichEdit; SearchText: string): Boolean;
function Form1.SearchForText_AndSelect(RichEdit: TRichEdit; SearchText: string): Boolean;
var
StartPos, Position, Endpos: Integer;
begin
StartPos := 0;
with RichEdit do
begin
Endpos := Length(RichEdit.Text);
Lines.BeginUpdate;
while FindText(SearchText, StartPos, Endpos, [stMatchCase])<> -1 do
begin
Endpos := Length(RichEdit.Text) - startpos;
Position := FindText(SearchText, StartPos, Endpos, [stMatchCase]);
Inc(StartPos, Length(SearchText));
SetFocus;
SelStart := Position;
SelLength :=
Length(SearchText);
end;
Lines.
EndUpdate;
end;
end;
Использование
procedure Form1.Edit1Change(Sender: TObject);
begin
SearchForText_AndSelect(
RichEdit1,
Edit1.Text);
end;
Возврат к списку