function 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;这个函数还包含了替换,你自己修改一下吧。
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;这个函数还包含了替换,你自己修改一下吧。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货