Giusto per la cronaca se qualcuno vuole dedicargli 5 minuti, ho scritto questo:
codice:
unit SinRichEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls, ComCtrls, Windows, Messages, Dialogs,
Graphics;
type
TSinRichEdit = class(TRichEdit)
procedure Change; override;
private
FWords: string;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
published
property Word: string read FWords write FWords;
end;
procedure Register;
implementation
constructor TSinRichEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure TSinRichEdit.Change;
var i:integer;
LastSelStart: integer;
begin
if Word='' then Exit;
for i:=1 to Length(Self.Text)-Length(Word)+1 do
begin
if Copy(Self.Text,i,Length(Word))=Word then
begin
LastSelStart := Self.SelStart;
Self.SelStart := i-1;
Self.SelLength := Length(Word);
Self.SelAttributes.Style := [fsBold];
Self.SelStart := LastSelStart;
Self.SelLength := 0;
Self.SelAttributes.Style := [];
end
else
begin
//showmessage('-'+Copy(Self.Text,i,Length(Word))+'-');
end;
end;
end;
procedure Register;
begin
RegisterComponents('EdoComponents', [TSinRichEdit]);
end;
end.
Mettetelo in un package e installatelo. Provate a metterlo su un form di prova e vedrete quali sono i problemi... Proma di usarlo però dovete settare la proprietà "Word" con la parola che volete evidenziare... dopodichè scrivete un breve testo a runtime di 15-20 righe contenente 20-30 volte la parola da evidenziare e vedrete...