如果可能添加另一combobox2,combobox1.text 必定是richedit1的子串,用combobox1.text替换在richedit中的字符串为combobox2.text值的.

解决方案 »

  1.   

    用这个函数function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
        replaceDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
        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
        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 Richedit1.'), mtError, [mbOk], 0);
        end;
    end;