Registriert seit: 29. Nov 2003
Ort: San Diego, CA/USA
1.446 Beiträge
Delphi 2006 Architect
|
Re: Reservierte Wörter hervorheben [RichEdit]
10. Dez 2006, 10:08
Delphi-Quellcode:
unit ufoMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
function IsReservedWord( const aReservedWord: String): Boolean;
function SpecialCases( const aReservedWord: String): Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
function TForm1.IsReservedWord( const aReservedWord: String): Boolean;
const
coReserved: Array[1..115] of String = (' and', ' else', ' inherited', ' packed',
' then', ' array', ' end', ' end;', ' end.', ' initialization', ' procedure',
' threadvar', ' as', ' except', ' inline', ' program', ' to', ' asm', ' exports',
' interface', ' property', ' try', ' begin', ' file', ' is', ' raise', ' type',
' case', ' final', ' label', ' record', ' unit', ' class', ' finalization',
' library', ' repeat', ' unsafe', ' const', ' finally', ' mod', ' resourcestring',
' until', ' constructor', ' for', ' nil', ' sealed', ' uses', ' destructor',
' function', ' not', ' set', ' var', ' dispinterface', ' goto', ' object', ' shl',
' while', ' div', ' if', ' of', ' shr', ' with', ' do', ' implementation', ' or',
' static', ' xor', ' downto', ' in', ' out', ' string', ' absolute', ' dynamic',
' local', ' platform', ' requires', ' abstract', ' export', ' message', ' private',
' resident', ' assembler', ' external', ' name', ' protected', ' safecall',
' automated', ' far', ' near', ' public', ' stdcall', ' cdecl', ' forward',
' nodefault', ' published', ' stored', ' contains', ' implements', ' overload',
' read', ' varargs', ' default', ' index', ' override', ' readonly', ' virtual',
' deprecated', ' package', ' register', ' write', ' dispid', ' library', ' pascal',
' reintroduce', ' writeonly');
var
CaseWord: String;
ReservedWord: String;
begin
CaseWord := LowerCase(Trim(aReservedWord));
Result := False;
for ReservedWord in coReserved do
begin
if ( ReservedWord = CaseWord ) then
begin
Result := True;
Exit;
end;
end;
end;
function TForm1.SpecialCases( const aReservedWord: String): Boolean;
var
CaseWord: String;
begin
CaseWord := LowerCase(aReservedWord);
Result := (Pos(' class(', CaseWord) > 0) or (Pos(' array[', CaseWord) > 0);
end;
end.
Um etwas Neues zu schaffen muss man seine Ohren vor den Nein-sagern verschliessen um seinen Geist öffnen zu können.
(George Lukas)
|