Możesz wykorzystać zwykły TRichEdit i według wyjątków (składni) kolorować w dowolnej formie zdefiniowane przez siebie słowa.
Kopiuj
uses
StrUtils;
procedure TFormApp1.KonwertujKod(const Lista: TStringList);
const
Keywords: array[0..36] of string = (
'and'
,'array'
,'as'
,'begin'
,'case'
,'const'
,'div'
,'do'
,'downto'
,'else'
,'end'
,'except'
,'finally'
,'for'
,'function'
,'if'
,'in'
,'is'
,'nil'
,'not'
,'of'
,'on'
,'or'
,'procedure'
,'raise'
,'record'
,'repeat'
,'set'
,'shl'
,'shr'
,'then'
,'to'
,'try'
,'until'
,'var'
,'while'
,'with'
);
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;
RE_Kod.Lines.AddStrings(Lista);
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;
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;
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;