
12.04.2010, 15:57
|
 |
Активный
|
|
Регистрация: 12.09.2008
Сообщения: 275
Репутация: 43
|
|
Код:
var
j, l, Count :integer;
s:string;
textpos :string;
begin
Count:=0;
textpos:=edit1.Text;
for j:=0 to RichEdit1.Lines.Count-1 do
begin
s:= RichEdit1.Lines[j];
l := Pos(textpos, s);
if l <> 0 Then
begin
RichEdit1.SelStart:= Count+l-1;
RichEdit1.SelLength:=length(textpos);
RichEdit1.SelAttributes.Color:= clRed;
end;
Count:=Count+LENGTH(S)+2;
end;
end;
вот еще
Код:
Function TextColor(RE :TrichEdit; const TextPos :string; TextColor :TColor):integer;
var
j, l, Count :integer;
s:string;
begin
Result:=0;
Count:=0;
for j:=0 to RE.Lines.Count-1 do
begin
s:= RE.Lines[j];
l := Pos(textpos, s);
if l <> 0 Then
begin
RE.SelStart:= Count+l-1;
RE.SelLength:=length(textpos);
RE.SelAttributes.Color:= TextColor;
inc(result);
end;
Count:=Count+LENGTH(S)+2;
end;
end;
Код:
ShowMessage('Закрашено '+IntToStr(TextColor(RichEdit1, Edit1.Text, clRed))+' вхождений текста');
проверено на Delphi 7
|