Możesz wykorzystać zwykły TRichEdit i według wyjątków (składni) kolorować w dowolnej formie zdefiniowane przez siebie słowa.
uses
StrUtils;
{{Konwertuje i koloruje wczytany kod źródłowy}
procedure TFormApp1.KonwertujKod(const Lista: TStringList);
const
{Mniej powszechne zostały wykomentowane, aby przyśpieszyć konwersję}
Keywords: array[0..36] of string = (//'abstract'
'and'
,'array'
,'as'
,'begin'
,'case'
//,'class'
,'const'
//,'constructor'
//,'deprecated'
//,'destructor'
,'div'
,'do'
,'downto'
,'else'
,'end'
,'except'
//,'export'
//,'file'
,'finally'
,'for'
,'function'
//,'goto'
,'if'
//,'implementation'
,'in'
//,'inherited'
//,'initialization'
//,'interface'
,'is'
//,'library'
//,'message'
//,'mod'
,'nil'
,'not'
//,'object'
,'of'
,'on'
,'or'
//,'overload'
//,'override'
//,'packed'
//,'platform'
//,'private'
,'procedure'
//,'program'
//,'property'
//,'protected'
//,'public'
//,'published'
,'raise'
,'record'
,'repeat'
,'set'
,'shl'
,'shr'
//,'string'
,'then'
//,'threadvar'
,'to'
,'try'
//,'type'
//,'unit'
,'until'
//,'uses'
,'var'
//,'virtual'
,'while'
,'with'
//,'xor'
);
//Arithmetics: array[0..9] of string = (';','>','<','[',']','+','=',':','*','/');
Numbers: array[0..11] of string = ('0','1','2','3','4','5','6','7','8','9','.',',');
var
s: string;
Pomin: Boolean;
i, nPos1, nPos2: SmallInt;
begin
RE_Kod.Clear;
RE_Kod.Repaint;
RE_Kod.Refresh;
{Wczytanie ze StringList}
RE_Kod.Lines.AddStrings(Lista);
{Kolorowanie kodu - słowa kluczowe}
for s in Keywords do
begin
i := 1;
Application.ProcessMessages;
repeat
Pomin := False;
nPos1 := PosEx(s, RE_Kod.Text, i);
if Copy(RE_Kod.Text, nPos1-1, 1)[1] in ['A'..'Z','a'..'z'] then Pomin := True;
if not Pomin then
begin
RE_Kod.SelAttributes.Color := $00FF8000;
RE_Kod.SelAttributes.Style := [fsBold];
RE_Kod.SelStart := nPos1-1;
RE_Kod.SelLength := Length(s);
end;
i := nPos1 + Length(s);
RE_Kod.SelAttributes.Color := clBlack;
RE_Kod.SelAttributes.Style := [];
until nPos1 = 0;
end;
{Kolorowanie kodu - Liczby}
for s in Numbers do
begin
i := 1;
Application.ProcessMessages;
repeat
nPos1 := PosEx(s, RE_Kod.Text, i);
RE_Kod.SelAttributes.Color := $000071E1;
RE_Kod.SelStart := nPos1-1;
RE_Kod.SelLength := Length(s);
i := nPos1 + Length(s);
RE_Kod.SelAttributes.Color := clBlack;
RE_Kod.SelAttributes.Style := [];
until nPos1 = 0;
end;
(*
{Kolorowanie kodu - Operatory artmetyczne}
for s in Arithmetics do
begin
i := 1;
Application.ProcessMessages;
repeat
nPos1 := PosEx(s, RE_Kod.Text, i);
RE_Kod.SelAttributes.Color := clPurple;
RE_Kod.SelStart := nPos1-1;
RE_Kod.SelLength := Length(s);
i := nPos1 + Length(s);
RE_Kod.SelAttributes.Color := clBlack;
RE_Kod.SelAttributes.Style := [];
until nPos1 = 0;
end;
*)
{Kolorowanie kodu - Komentarze}
i := 1;
repeat
nPos1 := PosEx('{', RE_Kod.Text, i);
RE_Kod.SelAttributes.Color := clGreen;
RE_Kod.SelAttributes.Style := [fsItalic];
RE_Kod.SelStart := nPos1-1;
nPos2 := PosEx('}', RE_Kod.Text, nPos1) + 1;
RE_Kod.SelLength := nPos2 - nPos1;
i := nPos2 + 1;
RE_Kod.SelAttributes.Color := clBlack;
RE_Kod.SelAttributes.Style := [];
until nPos1 = 0;
end;