怎样使用查找替换对话框(50分)

  • 主题发起人 主题发起人 笑三少2002
  • 开始时间 开始时间

笑三少2002

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,查找对话框上的"全替换",应该怎样做呢?

我编出的查找只能"查找下一个","替换",而不能实现"全替换"的功能,请各位高手支支招!
这里先行谢谢!
 
稍微一改就行了。
procedure TForm1.Button1Click(Sender: TObject);
var
tofind: string;
begin
richedit.SelStart := 0;
if Fedit.text <> '' then
while find(tofind) do
richedit.SelAttributes.Color := clRed; //这里是你对找到的字符串的属性修改
end;

function TForm1.find(tofind: string): boolean;
var
FindIn,findin2: string;
flen,start,holder,found,index: integer;
begin
result := True;
ToFind := lowercase(fedit.text);
findin := lowercase(richedit.text);
flen := length(tofind);
found := 0;
index := -1;
start := richedit.selstart;
if lowercase(richedit.seltext) = lowercase(tofind) then
richedit.perform(em_setsel, start +flen, start +flen);
start := richedit.selstart;
holder := start +1;
while found = 0 do
begin
if holder > (richedit.gettextlen)+223 then
begin
ActiveControl := richedit;
result := false;
exit;
end;
findin2 := concat(' ',copy(findin,holder,250),' ');
found := pos(tofind, findin2);
holder := holder + 225;
index := index +1;
end;
if index > 0 then index := index *225 else index := 0;
holder := start +index +found-3;
ActiveControl := richedit;
richedit.perform(em_setsel, holder, holder +flen);
richedit.perform(em_scrollcaret, 0,0);
end;
 
接受答案了.
 
后退
顶部