L laohe Unregistered / Unconfirmed GUEST, unregistred user! 2002-10-27 #1 例如我在将文件中的"你好"改为红色 文件中有很多"你好",不只一个,我想让其中所有的都改为红色
J jsxjd Unregistered / Unconfirmed GUEST, unregistred user! 2002-10-27 #2 procedure TForm1.Button1Click(Sender: TObject); begin with RichEdit1 do begin lines.clear; lines.add('说明:大家好!'); SelStart:=7; SelLength :=8; SelAttributes.color:=$0000ff; lines.add('说明:大家好!'); SelStart:=17; SelLength :=4; SelAttributes.color:=$00ff00; SelAttributes.size:=20; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin with RichEdit1 do begin lines.clear; lines.add('说明:大家好!'); SelStart:=7; SelLength :=8; SelAttributes.color:=$0000ff; lines.add('说明:大家好!'); SelStart:=17; SelLength :=4; SelAttributes.color:=$00ff00; SelAttributes.size:=20; end; end;
J jsxjd Unregistered / Unconfirmed GUEST, unregistred user! 2002-10-27 #3 以上是参考代码,这时是你要的代码: procedure TForm1.Button7Click(Sender: TObject); var pchar; m,n,ns:integer; s:string; begin s:='你好'; ns:=length(s); richedit1.Clear; richedit1.Lines.Add('在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('在地ddd一你dddd好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); p:=pchar(richedit1.text); m:=0; while true do begin n:=pos(s,p); if n=0 then break; inc(m,n); richedit1.SelStart:=m; richedit1.SelLength:=ns; richedit1.SelAttributes.color:=$0000ff; richedit1.SelAttributes.size:=20; inc(p,n+ns); inc(m,ns); end; richedit1.SelStart:=0; richedit1.SelLength:=0; end;
以上是参考代码,这时是你要的代码: procedure TForm1.Button7Click(Sender: TObject); var pchar; m,n,ns:integer; s:string; begin s:='你好'; ns:=length(s); richedit1.Clear; richedit1.Lines.Add('在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('在地ddd一你dddd好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); richedit1.Lines.Add('aaaaa在地一你好AAA在一五彩缤纷'); p:=pchar(richedit1.text); m:=0; while true do begin n:=pos(s,p); if n=0 then break; inc(m,n); richedit1.SelStart:=m; richedit1.SelLength:=ns; richedit1.SelAttributes.color:=$0000ff; richedit1.SelAttributes.size:=20; inc(p,n+ns); inc(m,ns); end; richedit1.SelStart:=0; richedit1.SelLength:=0; end;