RichEdit中实现查找功能
想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的RichEdit中实现查找功能教程,一起来看看吧!超容易上手~
C++ Builder
请参照Delphi的例子
Delphi
procedure TMainForm.FindDialogFind(Sender: TObject);
!-- frame contents -- !-- /frame contents -- var
FoundAt: LongInt;
StartPos, ToEnd: integer;
SearchFlag: TSearchTypes;
begin
if frMatchCase in FindDialog.Options then
SearchFlag:=[stMatchCase];
if frWholeWord in FindDialog.Options then
SearchFlag:=SearchFlag+[stWholeWord];
with RichEdit do
begin
StartPos:=SelStart+SelLength;
ToEnd:=Length(Text) - StartPos;
FoundAt:=FindText(FindDialog.FindText, StartPos, ToEnd, [stMatchCase]);
if FoundAt<>-1 then
begin
SetFocus;
SelStart:=FoundAt;
SelLength:=Length(FindDialog.FindText);
end
else
begin
SelLength:=0;
SelStart:=StartPos;
Application.MessageBox(PChar(找不到+FindDialog.FindText),查找失败,0);
end;
end;
end;