Is there an example of syntax highlighting for DScintilla?

I installed DScintilla , the Delphi VCL shell for Scintilla , but I cannot find a fundamental example of how to use it.

Could you post an example of the basic syntax highlighting code or a link to sample code for it?

+6
source share
2 answers

A very interesting library, but it's hard to say exactly what you want to do with it. Here is an example, for example, with some basic color settings for Pascal syntax. Please note that you need to have the SciLexer.dll library in the project folder (or the one where the application is looking for it).

This library wrapper provides many functions with meaningful names, so I’ll be the best to look at them as I see fit.

 uses DScintillaTypes, DScintilla; procedure TForm1.Button1Click(Sender: TObject); var Scintilla: TDScintilla; begin Scintilla := TDScintilla.Create(Self); // creating it dynamically, it also available as a component, so you don't need to do this Scintilla.DllModule := 'SciLexer.dll'; // the syntax library Scintilla.Align := alClient; // object alignment to the whole parent Scintilla.Parent := Self; // setting up the parent Scintilla.SetLexer(SCLEX_PASCAL); // and setting the syntax highlighter, see SCLEX_ types in DScintillaTypes.pas Scintilla.StyleSetBack(STYLE_DEFAULT, clBlack); // setting up the default background color Scintilla.StyleSetFore(SCE_PAS_DEFAULT, clWhite); // Pascal specific default fore color Scintilla.StyleSetBack(SCE_PAS_DEFAULT, clBlack); // Pascal specific default back color Scintilla.StyleSetFore(SCE_PAS_IDENTIFIER, clYellow); // Pascal specific identifier fore color Scintilla.StyleSetBack(SCE_PAS_IDENTIFIER, clBlack); // Pascal specific identifier back color Scintilla.StyleSetBold(SCE_PAS_IDENTIFIER, True); // Pascal specific identifier bold font style Scintilla.StyleSetUnderline(SCE_PAS_IDENTIFIER, True); // Pascal specific identifier underline font style Scintilla.StyleSetFore(SCE_PAS_COMMENT, RGB(243, 236, 255)); // etc. Scintilla.StyleSetBack(SCE_PAS_COMMENT, clBlack); Scintilla.StyleSetFore(SCE_PAS_COMMENT2, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_COMMENT2, clBlack); Scintilla.StyleSetFore(SCE_PAS_COMMENTLINE, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_COMMENTLINE, clBlack); Scintilla.StyleSetFore(SCE_PAS_NUMBER, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_NUMBER, clBlack); Scintilla.StyleSetFore(SCE_PAS_HEXNUMBER, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_HEXNUMBER, clBlack); Scintilla.StyleSetFore(SCE_PAS_WORD, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_WORD, clBlack); Scintilla.StyleSetFore(SCE_PAS_STRING, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_STRING, clBlack); Scintilla.StyleSetFore(SCE_PAS_STRINGEOL, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_STRINGEOL, clBlack); Scintilla.StyleSetFore(SCE_PAS_CHARACTER, RGB(243, 236, 255)); Scintilla.StyleSetBack(SCE_PAS_CHARACTER, clBlack); Scintilla.StyleSetFore(SCE_PAS_OPERATOR, clRed); Scintilla.StyleSetBack(SCE_PAS_OPERATOR, clBlack); Scintilla.StyleSetFore(SCE_PAS_ASM, clRed); Scintilla.StyleSetBack(SCE_PAS_ASM, clBlack); end; 
+4
source

I never did this, but it looks like you need to install lexer and then send the keywords via the SCI_SETKEYWORDS message (it's just a string of lines separated by a single space).

Here is an example in C ++:

http://tortoisesvn.googlecode.com/svn/trunk/src/TortoiseBlame/Lexer.cpp

I see that dScintilla has wrapped up in TDScintilla.SetKeyWords (), so I think it should work the same.

In any case, I agree that it will be very useful to find a more complete demonstration on how to use DScintilla.

+3
source

Source: https://habr.com/ru/post/899550/


All Articles