unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
const
// °Ë»çÇÒ Å°¿öµåµé...
keywords: array [1..28] of String =
('procedure', 'function', 'begin', 'end', 'whilw',
'do', 'with', 'if', 'try', 'finally',
'interface', 'uses', 'type', 'private' ,'public',
'var', 'const', 'implementation', 'class', 'array',
'of', 'string' ,'integer', 'unit', 'to',
'while', 'for', 'then');
var
i, n: Integer;
begin
with RichEdit1 do
begin
Lines.BeginUpdate; // º¯µ¿»çÇ×À» Àá½Ã ¸·´Â´Ù
try
for i := Low(keywords) to High(keywords) do
begin
n := 0;
while n >= 0 do
begin
n:= FindText(keywords[i], n, GetTextLen-n, [stWholeWord]);
if n >= 0 then
begin
SelStart := n;
SelLength := Length(keywords[i]);
SelAttributes.color := clBlue;
SelLength := 0;
n := n + Length(keywords[i]); // °Ë»öµÈ ´ÙÀ½ ±ÛÀÚºÎÅÍ...
end;
end;
end;
finally
Lines.EndUpdate;
end;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
RichEdit1.Lines.LoadFromFile('unit1.pas');
Button1Click(Sender);
end;
end. |
|