点击ReplaceDialog组件图标 里边有onfind和DialogReplace事件procedure TForm1.ReplaceDialogFind(Sender: TObject);//替换窗体ReplaceDialog的onfind事件
var
SearchType:TSearchTypes;//替换OnFind
begin
with ReplaceDialog do
begin
if frMatchCase in Options then
SearchType:=SearchType+[stMatchCase];
if frWholeWord in Options then
SearchType:=SearchType+[stWholeWord];
PerformFind(Sender,FindText,SearchType);
end;
RichEdit.SetFocus;
SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
end;
procedure TForm1.ReplaceDialogReplace(Sender: TObject); //替换框体的OnReplace事件
var
SearchType:TSearchTypes;
FoundAt, StartPos, ToEnd: Integer;
str:string;
label Start, Start1, Start2;
begin
with ReplaceDialog do
begin //1
if frReplace in Options then
begin//2
if frMatchCase in Options then
SearchType:=SearchType+[stMatchCase];
if frWholeWord in Options then
SearchType:=SearchType+[stWholeWord];
if RichEdit.Seltext = ReplaceDialog.FindText then
begin
RichEdit.SelText:= ReplaceDialog.ReplaceText;
Start1: StartPos:=RichEdit.SelStart+RichEdit.SelLength;
ToEnd:= RichEdit.GetTextLen-StartPos;
FoundAt := RichEdit.FindText(ReplaceDialog.FindText,StartPos,ToEnd,SearchType);
if FoundAt<>-1 then
begin
RichEdit.SelStart:=FoundAt;
RichEdit.SelLength:=Length(ReplaceDialog.FindText);
if RichEdit.Seltext='' then
begin
RichEdit.Selstart:=RichEdit.Selstart+2;
goto Start1;
end;
SendMessage(RichEdit.Handle, EM_SCROLLCARET, 0, 0);
end
else
begin
Str:= '找不到 '''''+ReplaceDialog.FindText+'''''';
Application.MessageBox(PChar(Str),'记事本',MB_ICONINFORMATION);
end;
end
else
begin
Start2: StartPos:=RichEdit.SelStart+RichEdit.SelLength;
ToEnd:= RichEdit.GetTextLen-StartPos;
FoundAt := RichEdit.FindText(ReplaceDialog.FindText,StartPos,ToEnd,SearchType);
if FoundAt<>-1 then
begin
RichEdit.SelStart:=FoundAt;
if RichEdit.Seltext='' then
RichEdit.SelLength:=Length(ReplaceDialog.FindText);
begin
RichEdit.Selstart:=RichEdit.Selstart+2;
goto Start2;
end;
SendMessage(RichEdit.Handle, EM_SCROLLCARET, 0, 0);
end
else
begin
Str:= '找不到 '''''+ReplaceDialog.FindText+'''''';
Application.MessageBox(PChar(Str),'记事本',MB_ICONINFORMATION);
end;
end;
end;
if frReplaceAll in Options then
begin
if frMatchCase in Options then
SearchType:=SearchType+[stMatchCase];
if frWholeWord in Options then
SearchType:=SearchType+[stWholeWord];
if RichEdit.Seltext = ReplaceDialog.FindText then
RichEdit.SelText:= ReplaceDialog.ReplaceText;
FindTextOld:='';
PerformFind(Sender,FindText,SearchType);
while PerformFind(Sender,FindText,SearchType) do
begin
RichEdit.SelText:= ReplaceDialog.ReplaceText;
end;
end;
end;
RichEdit.SetFocus;
SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
end;
procedure TForm1.ReplaceDialogFind(Sender: TObject);
var
SearchType:TSearchTypes;//替换OnFind
begin
with ReplaceDialog do
begin
if frMatchCase in Options then
SearchType:=SearchType+[stMatchCase];
if frWholeWord in Options then
SearchType:=SearchType+[stWholeWord];
PerformFind(Sender,FindText,SearchType);
end;
RichEdit.SetFocus;
SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
end;
|