Table of Contents

The syntax highlighting memo

Using the memo

TScrMemo is a memo control that shows scripts with syntax highlighting. To use it, drop a TScrMemo on the form together with a styler component for the script language, and assign the styler to the TScrMemo.SyntaxStyles property:

Language Styler component
Pascal TScrPascalMemoStyler (unit ScrMps)
Basic TScrBasicMemoStyler (unit ScrMbs)
JavaScript TScrJavaScriptMemoStyler (unit ScrMjs)

When the styler is assigned, the text in the memo is rendered with the syntax highlighting of the language. You can also switch the syntax highlighting at runtime by assigning another styler:

ScrMemo1.SyntaxStyles := ScrJavaScriptMemoStyler1;

To change the colors of the syntax highlighting, use the properties of the styler: the text and background colors and the font of comments and numbers are in the CommentStyle and NumberStyle properties, and the ones of keywords, symbols and strings are in the items of the AllStyles property.

The stylers have predefined keywords for their language. To highlight other words, for example the names of objects your application provides to scripts, add a TElementStyle item to the AllStyles property, set its StyleType to stKeyword and add the words to its KeyWords list.

TScrMemo has a gutter that displays the line numbers of the source code. It can also display executable lines, breakpoints and the active line, which is what the debugging tools of TMS Scripter do. Use these public properties to do it in your own code:

TScrMemo.ActiveLine: Integer;

Sets the active source code line, displayed in the active line colors.

TScrMemo.BreakPoint[RowIndex]: Boolean;

When true, the line has a breakpoint. Only executable lines can have breakpoints; the debugging methods of the scripter tell which lines are executable. A breakpoint is displayed as a red line with white font.

TScrMemo.Executable[RowIndex]: Boolean;

When true, the gutter shows a marker that the line is executable.

To run the script typed in the memo, assign the memo lines to the scripter TatCustomScripter.​Source​Code property and execute it:

Scripter.SourceCode.Assign(ScrMemo1.Lines);
Scripter.Execute;