I have installed DScintilla
, Delphi VCL wrapper for Scintilla
code editing component, but I can't find any basic example of how to use it.
Could you post some basic code example of syntax highlighting or a reference to code examples for it ?
Very interesting library but hard to say what exactly want you do with it.
Here for instance is the example with some basic color settings for Pascal syntax highlighter. Note that you need to have the SciLexer.dll
library in your project folder (or the one where the application looks for it).
This library wrapper provides many features with meaningful names so the best I think would be to browse them by your own.
uses
DScintillaTypes, DScintilla;
procedure TForm1.Button1Click(Sender: TObject);
var
Scintilla: TDScintilla;
begin
Scintilla := TDScintilla.Create(Self); // creating it dynamically, it's 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;
I never did that, but seems that you have to set the lexer and then send the keywords via the SCI_SETKEYWORDS message (it's just a string chain separated with a single space).
Here is an example in C++:
http://tortoisesvn.googlecode.com/svn/trunk/src/TortoiseBlame/Lexer.cpp
I see that dScintilla has that wrapped in TDScintilla.SetKeyWords(), so I guess it should work the same way.
In any case I agree that it will be very helpful to find a more complete demo on how to use DScintilla.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With