procedure TForm1.Button1Click(Sender: TObject);
const
word: array[1..32] of string[15] = ('if','then','else','begin','end','for','to',
'do','while','repeat','until','case','of','type','var','const','procedure',
'function','array','string','unit','interface','uses','class','private',
'public','implementation','in','and','or','xor','not');
comment: array[1..6] of string[2] = ('{','}','(*','*)','//',#13#10);
var
k,k1,i: integer;
begin
for i:=1 to length(word) do
begin
k:=-length(word[i]);
repeat
k:=RichEdit1.FindText(word[i],k+length(word[i]),
length(RichEdit1.Text)-k-length(word[i]),[stWholeWord]);
RichEdit1.SelStart:=k;
RichEdit1.SelLength:=length(word[i]);
RichEdit1.SelAttributes.Style:=[fsBold];
RichEdit1.SelAttributes.Color:=clNavy;
until k < 0;
end;
for i:=0 to 2 do
begin
k1:=-length(comment[i*2+1]);
repeat
k:=k1;
k:=RichEdit1.FindText(comment[i*2+1],k+length(comment[i*2+1]),
length(RichEdit1.Text)-k-length(comment[i*2+1]),[stMatchCase]);
k1:=RichEdit1.FindText(comment[i*2+2],k+length(comment[i*2+2]),
length(RichEdit1.Text)-k-length(comment[i*2+2]),[stMatchCase]);
RichEdit1.SelStart:=k;
RichEdit1.SelLength:=k1-k+length(comment[i*2+2]);
RichEdit1.SelAttributes.Style:=[fsItalic];
RichEdit1.SelAttributes.Color:=clNavy;
until k < 0;
end;
end;