delphi ReplaceDialog 组件的使用
请各位大侠帮下忙 怎么实现ReplaceDialog组件的区别 替换和全部替换啊 就是说怎么判断点了哪一个 谢谢了点击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+;
if frWholeWord in Options then
SearchType:=SearchType+;
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+;
if frWholeWord in Options then
SearchType:=SearchType+;
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+;
if frWholeWord in Options then
SearchType:=SearchType+;
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+;
if frWholeWord in Options then
SearchType:=SearchType+;
PerformFind(Sender,FindText,SearchType);
end;
RichEdit.SetFocus;
SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
end; unction TForm1.PerformFind(Sender: TObject; FindString: String; SearchType: TSearchTypes):Boolean;//自定义过程,查找下一个
var
FoundAt, StartPos, ToEnd: Integer;
str:string;
label Start;
begin
if FindTextOld = FindString then
with RichEdit do
begin
Start: StartPos:=SelStart+SelLength;
ToEnd:=GetTextLen-StartPos;
FoundAt:=FindText(FindString,StartPos,ToEnd,SearchType);
if FoundAt<>-1 then
begin
SelStart:=FoundAt;
SelLength:=Length(FindString);
if Seltext='' then
begin
Selstart:=Selstart+2;
goto Start;
end;
Result:=True;
end
else
begin
str:= '找不到 '''''+PChar(FindString)+'''''';
Application.MessageBox(PChar(str),'记事本',MB_ICONINFORMATION);
FindDialog.CloseDialog;
Result:=False;
end;
end
else
begin
FindTextOld:= FindString;
Result:=True;
end;
end; 写的好长啊
页:
[1]