|
Jak podświetlić kod HTML w kontrolce RichEdit? |
|
|
|
Napisał: Berl
|
|
sobota, 01 październik 2005 |
|
Do podświetlania kodu HTML w kontrolce RichEdit można użyć następującej funkcji :
procedure HighLightHTML(RichEdit: TRichEdit; KolorTekstu, KolorTaga, KolorStringa: TColor);
var
i, Str : Integer;
s : string;
CzyTag, CzyString : Boolean;
Kolor : TColor;
begin
Str := 0;
CzyString := False;
CzyTag := False;
Kolor := KolorTekstu;
RichEdit.SetFocus;
for i := 0 to Length(RichEdit.Text) do begin
RichEdit.SelStart := i;
RichEdit.SelLength := 1;
s := RichEdit.SelText;
if (s = '<') or (s = '{') then CzyTag := True;
if CzyTag then begin
if (s = '"') then begin
if not CzyString then begin
Str := 1;
CzyString := True;
end
else CzyString := False;
end;
end;
if CzyTag then begin
if CzyString then begin
if Str <> 1 then Kolor := KolorStringa;
end
else Kolor := KolorTaga
end
else Kolor := KolorTekstu;
RichEdit.SelAttributes.Color := Kolor;
Str := 0;
if (s = '>') or (s = '}') then CzyTag := False;
end;
RichEdit.SelLength := 0;
end;
Najlepsze efekty uzyskamy wywołując tą procedurę pomiędzy procedurami TRichEdit.Lines.BeginUpdate i TRichEdit.Lines.EndUpdate, gdyż bez nich będzie widać, jak tagi są zamieniane.
Aby dodać komentarz zaloguj się. Jeśli nie masz konta, załóż je sobie. Tylko zarejestrowani użytkownicy mogą pisać komentarze. |