1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| procedure RE_ColorerMots(RE: TRichEdit; Mot: ShortString; AColor: TColor; var Count: integer);
//< Colorier toutes les occurences de Mot avec AColor, Count renvoie le nombre de mots coloriés
// 3 secondes 838 ms pour colorier 4784 fois Mot dans Zola992K.txt de 992 Ko
label Recomm;
var
pCherche, pTexte, pCour: PChar;
tt: Integer; // Taille texte
begin
Count := 0;
with RE do
begin
GetMem(pCherche, 1 + length(Mot));
StrPCopy(pCherche, Mot);
tt := RE.GetTextLen + 1;
pTexte:=@RE.text[1];
SetFocus;
Recomm:
// On commence à la position du Caret :
pCour := pTexte + SelStart + SelLength;
// Recherche :
pCour := StrPos(pCour, pCherche);
if pCour <> nil then
begin
inc(Count);
SelStart := pCour - pTexte;
SelLength := Length(Mot);
SelAttributes.Color := AColor;
goto Recomm;
end;
SelLength := 0;
FreeMem(pCherche, 1 + length(Mot));
end;
end; |
Partager