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;
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;本人是个菜鸟,希望有人把with语句给我还原下,在把这些语句每句的意思能给我祥解下!
看看所在类的是不是with的对象。是的话还原
var
SelPos: Integer;
RepDlg: TReplaceDialog;
begin
RepDlg := TReplaceDialog(Sender);
//对文本进行单个替换
if frReplace in RepDlg.Options then
begin SelPos := Pos(RepDlg.FindText, RichEdit1.Lines.Text);//Pos最好改用AnsiPos,否则会存在在"中国“当中找出”泄“字来类似的问题
if SelPos > 0 then
begin
RichEdit1.SelStart := SelPos - 1;
RichEdit1.SelLength := Length(RepDlg.FindText);
RichEdit1.SelText := RepDlg.ReplaceText;
end
else
MessageDlg(Concat('Could not find "', RepDlg.FindText, '" in Memo1.'), mtError, [mbOk], 0); end;
//对文本进行全部替换
if frReplaceAll in RepDlg.Options then
while true do
begin if SelPos=0 then
break;
SelPos := Pos(RepDlg.FindText, RichEdit1.Lines.Text);//Pos最好改用AnsiPos,否则会存在在"中国“当中找出”泄“字来类似的问题
if SelPos > 0 then
begin
RichEdit1.SelStart := SelPos - 1;
RichEdit1.SelLength := Length(RepDlg.FindText);
RichEdit1.SelText := RepDlg.ReplaceText;
end end;
end;
begin
//对文本进行单个替换
if frReplace in ReplaceDialog1.Options then
begin
with TReplaceDialog(Sender) do
begin
SelPos := Pos(FindText, RichEdit1.Lines.Text); //在主字符串中查找子串的位置
if SelPos > 0 then //子串的位置不为0,即找到子串
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;
end; 有事没事 Google一下 万事OK