![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как сделать подсветку синтаксиса с помощью HIlightMemo? [Delphi, Windows]
Greeg © (2006-12-11 11:45:00)Здравствуйте! Подскажите как правильно сделать подсветку синтаксиса в HIlightMemo! В OnScanTokenкак я не делал, всё не коректно получалось.
Greeg (2006-12-12 22:40:00) [1]Большое спасибо, всё работает!!!
mdw (2006-12-12 13:39:00) [2]Де еще, где нибудь при создании:
FReservedWords:= NewStrList;
for i:= 0 to ReservedWordsCount-1 do ReservedWords.Add(ReservedWords[i]);
FReservedWords.Sort(False);
mdw (2006-12-12 13:37:00) [3]У меня примерно так реализовано. Не работают мнонгострочные коментарии, лениво делать:
type TTokens = (tNone, tReservedWord, tComment, tCharStr, tDigital);
const ReservedWordsCount = 72;
ReservedWords: array [0..ReservedWordsCount-1]of string = (
'and', 'array', 'as', 'asm',
'begin', 'case', 'class', 'const',
'constructor', 'destructor', 'dispinterface', 'div',
'do', 'downto', 'else', 'end',
'except', 'exports', 'file', 'finalization',
'finally', 'for', 'function', 'goto',
'if', 'implementation', 'in', 'inherited',
'initialization', 'inline', 'interface', 'is',
'label', 'library', 'mod', 'nil',
'not', 'object', 'of', 'or',
'out', 'packed', 'procedure', 'program',
'property', 'raise', 'record', 'repeat',
'resourcestring', 'set', 'shl', 'shr',
'string', 'then', 'threadvar', 'to',
'try', 'type', 'unit', 'until',
'uses', 'var', 'while', 'with',
'xor', 'private', 'protected', 'public',
'published', 'automated', 'at', 'on'
);
const Separators = ' ;.,:=>
Greeg (2006-12-11 21:53:00) [4]Я не смог сделать, чтоб нормально подсвечивался синтаксис Паскаля! Была куча алгоритмов...Подсвечивается не всё! Мне нужен пример, чтоб хотябы begin подсвечивался нормально, иднентично Дельфийскому! Вот мой код...
function OnScanToken(Dumpy: Pointer; Sender: PControl; const FromPos: TPoint;
var Attrs: TTokenAttrs): Integer;
var
S, Word: String;
Idx, Len, c: Integer;
Ident: Boolean;
begin
S := AnsiLowerCase(Editor.Edit.Lines[FromPos.Y]);
Len := Length(S);
Result := 0;
Ident := FALSE;
if S = '' then Exit;
Idx := FromPos.X;
for c := 0 to WordList.Count - 1 do begin //Список зарезе.слов
Word := WordList.Items[c];
if AnsiCompareStr(Copy(S, Idx + 1, Length(Word)), Word) = 0 then
Ident := TRUE;
while (Idx < Len) and not (S[Idx + 1] in TSynWordBreakChars) and (Length(Word) > Idx - FromPos.X) do
Inc(Idx);
if Ident then
Break;
{ if Length(Word) < Idx - FromPos.X then
Ident := FALSE;
}
end;
// Result := Idx - FromPos.X;
Result := Length(Word);
if Ident then begin
Attrs.FontStyle := [fsBold];
Attrs.FontColor := clNavy;
Exit;
end else begin
Attrs.FontStyle := [];
Attrs.FontColor := clWindowText;
end;
FormMain.StatusText[0] := PChar(Format('FromPos [%d, %d], Len %d', [FromPos.X, FromPos.Y, Len]));
end;
Vladimir Kladov (2006-12-11 17:02:00) [5]есть же пример вроде.