Author: Jonas Bilinkevicius
How do I scan a TRichEdit from top to bottom and check for lines with a special
pattern to change color? I only know SelStart and SelLength, but how do I select a
line at a time?
Answer:
1 var2 S: string;
3 i: Integer;
4 5 { ... }6 with richedit1 do7 begin8 lines.beginupdate;
9 try10 for i := 0 to lines.count - 1 do11 begin12 S := Lines[i];
13 if LineShouldBeColored(S) then14 begin15 SelStart := Perform(EM_LINEINDEX, i, 0);
16 SelLength := Length(S);
17 SelAttributes.Color := clRed;
18 end;
19 end;
20 finally21 SelStart := 0;
22 Perform(EM_SCROLLCARET, 0, 0);
23 lines.endupdate;
24 end;
25 end;