鱼C论坛

 找回密码
 立即注册
查看: 3341|回复: 3

delphi ReplaceDialog 组件的使用

[复制链接]
发表于 2012-6-21 17:46:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
请各位大侠帮下忙 怎么实现ReplaceDialog  组件的区别 替换和全部替换啊 就是说怎么判断点了哪一个 谢谢了
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-6-27 14:09:50 | 显示全部楼层
点击ReplaceDialog组件图标 里边有onfind和DialogReplace事件
  1. procedure TForm1.ReplaceDialogFind(Sender: TObject);//替换窗体ReplaceDialog的onfind事件
  2. var
  3.   SearchType:TSearchTypes;//替换OnFind
  4. begin
  5.   with ReplaceDialog do
  6.   begin
  7.     if frMatchCase in Options then
  8.       SearchType:=SearchType+[stMatchCase];
  9.     if frWholeWord in Options then
  10.       SearchType:=SearchType+[stWholeWord];
  11.     PerformFind(Sender,FindText,SearchType);
  12.   end;
  13.   RichEdit.SetFocus;
  14.   SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
  15. end;

  16. procedure TForm1.ReplaceDialogReplace(Sender: TObject); //替换框体的OnReplace事件
  17. var
  18.   SearchType:TSearchTypes;
  19.   FoundAt, StartPos, ToEnd: Integer;
  20.   str:string;
  21.   label Start, Start1, Start2;
  22. begin
  23.   with ReplaceDialog do
  24.   begin //1
  25.   
  26.     if frReplace in Options then
  27.     begin//2
  28.       if frMatchCase in Options then
  29.         SearchType:=SearchType+[stMatchCase];
  30.       if frWholeWord in Options then
  31.         SearchType:=SearchType+[stWholeWord];

  32.       if RichEdit.Seltext = ReplaceDialog.FindText then
  33.       begin
  34.         RichEdit.SelText:= ReplaceDialog.ReplaceText;
  35.         Start1: StartPos:=RichEdit.SelStart+RichEdit.SelLength;
  36.         ToEnd:= RichEdit.GetTextLen-StartPos;
  37.         FoundAt := RichEdit.FindText(ReplaceDialog.FindText,StartPos,ToEnd,SearchType);

  38.         if FoundAt<>-1 then
  39.         begin
  40.           RichEdit.SelStart:=FoundAt;
  41.           RichEdit.SelLength:=Length(ReplaceDialog.FindText);
  42.           if RichEdit.Seltext='' then
  43.           begin
  44.             RichEdit.Selstart:=RichEdit.Selstart+2;
  45.             goto Start1;
  46.           end;
  47.           SendMessage(RichEdit.Handle, EM_SCROLLCARET, 0, 0);
  48.         end
  49.         else
  50.         begin
  51.           Str:= '找不到 '''''+ReplaceDialog.FindText+'''''';
  52.           Application.MessageBox(PChar(Str),'记事本',MB_ICONINFORMATION);
  53.         end;

  54.       end
  55.       else
  56.       begin
  57.         Start2: StartPos:=RichEdit.SelStart+RichEdit.SelLength;
  58.         ToEnd:= RichEdit.GetTextLen-StartPos;
  59.         FoundAt := RichEdit.FindText(ReplaceDialog.FindText,StartPos,ToEnd,SearchType);

  60.         if FoundAt<>-1 then
  61.         begin
  62.           RichEdit.SelStart:=FoundAt;
  63.           if RichEdit.Seltext='' then
  64.           RichEdit.SelLength:=Length(ReplaceDialog.FindText);
  65.           begin
  66.             RichEdit.Selstart:=RichEdit.Selstart+2;
  67.             goto Start2;
  68.           end;
  69.           SendMessage(RichEdit.Handle, EM_SCROLLCARET, 0, 0);
  70.         end
  71.         else
  72.         begin
  73.           Str:= '找不到 '''''+ReplaceDialog.FindText+'''''';
  74.           Application.MessageBox(PChar(Str),'记事本',MB_ICONINFORMATION);
  75.         end;
  76.       end;
  77.     end;

  78.     if frReplaceAll in Options then
  79.     begin
  80.       if frMatchCase in Options then
  81.         SearchType:=SearchType+[stMatchCase];
  82.       if frWholeWord in Options then
  83.         SearchType:=SearchType+[stWholeWord];
  84.       if RichEdit.Seltext = ReplaceDialog.FindText then
  85.          RichEdit.SelText:= ReplaceDialog.ReplaceText;
  86.       FindTextOld:='';
  87.       PerformFind(Sender,FindText,SearchType);

  88.       while PerformFind(Sender,FindText,SearchType) do
  89.       begin
  90.         RichEdit.SelText:= ReplaceDialog.ReplaceText;
  91.       end;
  92.     end;

  93.   end;
  94.   RichEdit.SetFocus;
  95.   SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
  96. end;

  97. procedure TForm1.ReplaceDialogFind(Sender: TObject);
  98. var
  99.   SearchType:TSearchTypes;//替换OnFind
  100. begin
  101.   with ReplaceDialog do
  102.   begin
  103.     if frMatchCase in Options then
  104.       SearchType:=SearchType+[stMatchCase];
  105.     if frWholeWord in Options then
  106.       SearchType:=SearchType+[stWholeWord];
  107.     PerformFind(Sender,FindText,SearchType);
  108.   end;
  109.   RichEdit.SetFocus;
  110.   SendMessage(RichEdit.Handle,EM_SCROLLCARET,0,0);
  111. end;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-6-27 14:13:09 | 显示全部楼层
  1. unction TForm1.PerformFind(Sender: TObject; FindString: String; SearchType: TSearchTypes):Boolean;//自定义过程,查找下一个
  2. var
  3.   FoundAt, StartPos, ToEnd: Integer;
  4.   str:string;
  5.   label Start;
  6. begin
  7.   if FindTextOld = FindString then
  8.     with RichEdit do
  9.     begin
  10.       Start: StartPos:=SelStart+SelLength;
  11.       ToEnd:=GetTextLen-StartPos;
  12.       FoundAt:=FindText(FindString,StartPos,ToEnd,SearchType);
  13.       if FoundAt<>-1 then
  14.       begin
  15.         SelStart:=FoundAt;
  16.         SelLength:=Length(FindString);
  17.         if Seltext='' then
  18.         begin
  19.           Selstart:=Selstart+2;
  20.           goto Start;
  21.         end;
  22.         Result:=True;
  23.       end
  24.       else
  25.       begin
  26.         str:= '找不到 '''''+PChar(FindString)+'''''';
  27.         Application.MessageBox(PChar(str),'记事本',MB_ICONINFORMATION);
  28.         FindDialog.CloseDialog;
  29.         Result:=False;
  30.       end;
  31.     end
  32.   else
  33.   begin
  34.     FindTextOld:= FindString;
  35.     Result:=True;
  36.   end;
  37. end;
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2014-10-17 08:59:32 | 显示全部楼层
写的好长啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-12 17:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表