RichEdit中实现查找功能
2008-03-08 21:31:51 来源:WEB开发网核心提示:RichEdit有一个FindText函数,极大方便了我们为RichEdit编制查找功能,RichEdit中实现查找功能,下面的片断取自于Delphi帮助中的范例, C++ Builder 请参照Delphi的例子 Delphi PRocedure TMainForm.FindDialogFind(Se
RichEdit有一个FindText函数,极大方便了我们为RichEdit编制查找功能。下面的片断取自于Delphi帮助中的范例。
C++ Builder
请参照Delphi的例子
Delphi
PRocedure TMainForm.FindDialogFind(Sender: TObject);
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;
C++ Builder
请参照Delphi的例子
Delphi
PRocedure TMainForm.FindDialogFind(Sender: TObject);
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;
更多精彩
赞助商链接