zoukankan      html  css  js  c++  java
  • 程序中的对话框应用(6)- “替换”对话框

    TReplaceDialog组件是TFindDialog类的特殊版本,提示用户查找和替换字符串,与“查找”对话框相同,替换对话框是一个无模式的windows对话框。

    代码示例(窗体上添加按钮、RichEdit、ReplaceDialog):

    procedure TForm1.Button1Click(Sender: TObject);//打开替换对话框
    begin
      ReplaceDialog1.Top:= 200;
      ReplaceDialog1.Left:= 400;
      ReplaceDialog1.Execute;
    end;
    
    procedure TForm1.ReplaceDialog1Find(Sender: TObject);//在文本中查找要替换的内容
    var
      FoundAt: LongInt;
      StartPos,Toend: integer;
    begin
      with RichEdit1 do
      begin
        if SelLength<> 0 then
        StartPos:= SelStart+ SelLength
        else
          StartPos:= 0;
        Toend:= Length(Text)- StartPos;
        FoundAt:= FindText(ReplaceDialog1.FindText,StartPos,Toend,[stMatchCase]);
        if FoundAt <> -1 then
        begin
          SetFocus;
          SelStart:= FoundAt;
          SelLength:= Length(ReplaceDialog1.FindText);
        end;
      end;
    end;
    
    procedure TForm1.ReplaceDialog1Replace(Sender: TObject);
    var
      SelPos: Integer;
    begin
      //对文本进行单个替换
      if frReplace in ReplaceDialog1.Options then
      begin
        with TReplaceDialog(Sender) do
        begin
          SelPos:= pos(FindText,RichEdit1.Lines.Text);
          if SelPos> 0 then
          begin
            RichEdit1.SelStart:= SelPos- 1;
            RichEdit1.SelLength:= Length(FindText);
            RichEdit1.SelText:= ReplaceText;
          end
          else
            MessageDlg(Concat('Could not find',Findtext,'in Memo1.'),mtError,[mbOK],0);
        end;
        //对文本进行全部替换
        if frReplaceAll in ReplaceDialog1.Options then
        while True do
        begin
          with TReplaceDialog(Sender) do
          begin
            if SelPos= 0 then
            Break;
          SelPos:= Pos(FindText,RichEdit1.Lines.Text);
            if SelPos> 0 then
            begin
              RichEdit1.SelStart:= SelPos- 1;
              RichEdit1.SelLength:= Length(FindText);
              RichEdit1.SelText:= ReplaceText;
            end;
          end;
        end;
      end;
    end;

     

  • 相关阅读:
    Linux Shell脚本详细教程
    linux下错误代码E212: Can't open file for writing
    github仓库的基本使用-创建、上传文件、删除
    -bash: ifconfig: command not found解决办法
    Xshell能ping通但连不上CentOS 7
    devtools和vuex mutations
    Google Chrome谷歌浏览器安装devtools
    Vuex状态管理模式
    vue Promise all
    vue Promise链式调用
  • 原文地址:https://www.cnblogs.com/fansizhe/p/12784190.html
Copyright © 2011-2022 走看看