TWebSyntaxMemo
Below is a list of the most important properties methods and events for the TWebSyntaxMemo
.
TWebSyntaxMemo
is using the external JavaScript written Ace editor.
![]() |
![]() |
---|---|
Designtime | Runtime |
Loading a file
Loading with TWebFilePicker
First the file should be retrieved as a text. This can be done in the TWebFilePicker
’s OnChange
event:
procedure TForm1.WebFilePicker1Change(Sender: TObject);
begin
//First nake sure that there's a file available
if Assigned(WebFilePicker1.Files[0]) then
begin
WebFilePicker1.Files[0].GetFileAsText;
//Additional code here
end;
end;
Then assign the retrieved text to the TWebSyntaxMemo
:
procedure TForm1.WebFilePicker1GetFileAsText(Sender: TObject;
AFileIndex: Integer; AText: string);
begin
WebSyntaxMemo1.Text := AText;
end;
Loading with drag and drop
For this approach a TWebFileReader
is needed. Once the file is read, the text content can be
assigned to the TWebSyntaxMemo
.
procedure TForm1.WebFormCreate(Sender: TObject);
begin
fr := TWebFileReader.Create(Self);
fr.OnReadDone := DoReadLoaded;
end;
procedure TForm1.DoReadLoaded(aFileName: string; AResult: JSValue);
begin
WebSyntaxMemo1.Text := JS.toString(AResult);
end;
What’s left to handle is the file reading itself when a file has been dropped onto the
TWebSyntaxMemo
. In the OnDragDrop
event, the following can be written:
procedure TForm1.WebSyntaxMemo1DragDrop(Sender, Source: TObject; X, Y:
Integer);
var
f: TJSHTMLFile;
begin
f := TJSDragEvent(TDragSourceObject(Source).Event).dataTransfer.files[0];
//Get the file
//Make sure it's available
if Assigned(f) then
fr.readAsBinaryString(f); //Read the file using the TWebFileReader
end;
Downloading a file
Downloading a file means a single line of code only.
For example with the code below, the contents of the editor can be downloaded to the test.txt file.
Properties for TWebSyntaxMemo
Property | Description |
---|---|
Autocompletion | There are 3 options: saNone to disable autocompletion, saLive to autocomplete during typing and saBasic to show autocompleting keywords by pressing Ctrl+Space. |
CaretPosition: Integer | Position of the caret. |
CustomAutocomplete | A collection of custom keywords that can be added to autocollection. Keyword highlighting is not available |
FadeFoldWidgets: Boolean | Enable or disable fading fold widgets. |
FixedGutterWidth: Boolean | Gutter width can be fixed up to 1000 lines. |
FontName: string | Name of the font. Only monospaced fonts will work. |
FontSize: Integer | Size of the font. |
HighlightActiveLine: Boolean | Highlight the line where the caret is |
Lines: TStringList | Access the editor’s content as a TStringList . |
Mode: TSyntaxMemoMode | Language mode for the editor. |
PersistentHorizontalScrollbar: Boolean | Always show horizontal scrollbar. |
PersistentVerticalScrollbar: Boolean | Always show vertical scrollbar. |
PrintMargin: Integer | Value of the print margin position. Default is 80 . |
ReadOnly: Boolean | Enable or disable read only mode. |
SelLength: Integer | Selection length. |
SelStart: Integer | Selection start. |
ShowFoldWidgets: Boolean | Hide or show the fold widgets. |
ShowGutter: Boolean | Hide or show the gutter. |
ShowIndentGuides: Boolean | Hide or show the indent guides. |
ShowInvisibles: Boolean | Hide or show the invisible characters such as whitespaces. |
ShowLineNumbers: Boolean | Hide or show the line numbers. |
ShowPrintMargin: Boolean | Hide or show the print margin. |
SoftTabs: Boolean | Enable or disable soft tabs. |
TextDirection: TSyntaxTextDirection | Text direction from left to right or right to left. |
TabSize: Integer | Size of the tab in spaces. |
Text: string | Access the editor’s content as a single string. |
Theme: TSyntaxMemoTheme | The theme of the editor. |
WordWrap | There are 4 options for wordwrapping: swNone means there’s no wordwrap, swPrintMargin will wrap at the print margin, swView will wrap at what’s visible and swValue will use the WordWrapValue to wrap at a configured length. |
WordWrapIndented: Boolean | Allow indenting in wordwrap. |
WordWrapValue: Integer | Wordwrap size. Only used if the WordWrap is set to swValue |
Methods for TWebSyntaxMemo
Method | Description |
---|---|
Clear | Clears the content of the editor. |
DisableLocalKeywords | Disables local keywords that are added constantly while content is being added to the editor. |
Find(AText: string) | Finds and highlights the AText (if exists) in the editor’s content. |
FindAll(AText: string) | Finds all and highlights the first AText (if exists) in the editor’s content. |
FindNext | Finds the next occurrence of the highlighted text. |
FindPrevious | Finds the previous occurrence of the highlighted text. |
Focus | Focuses the editor. |
InitializeKeyWords(ACompleter: TSyntaxCompleter) | Initialize a set of keywords with ACompleter . |
InsertText(AText: string) | Insert AText at the caret position. |
InsertText(APosition: TPoint; AText: string) | Insert AText at APosition . |
OpenSearchBox | Opens the editor’s searchbox. |
PreloadPascalKeywords | Earlier versions of Ace does not support Pascal keywords in autocompletion. With this function, they can be preloaded as autocompletion keywords. |
Redo | ‘Redo’ edit command. Redoes an undid change. |
RemoveSelectedText | Remove the selected text. |
RemoveCustomAutocompleter | Remove the added custom autocompleter |
RemovePascalKeywords | Earlier versions of Ace does not support Pascal keywords in autocompletion. With this function, they can be removed from autocompletion keywords if they had been added previously. |
Replace(AReplacement: string) | ‘Replace’ edit command. It replaces the selected text with AReplacement |
Replace(AText, AReplacement: string) | ‘Replace’ edit command. It replaces AText with AReplacement . |
ReplaceAll(AReplacement: string) | ‘Replace all’ edit command. It replaces all occurrences of the selected text with AReplacement . |
ReplaceAll(AText, AReplacement: string) | ‘Replace all’ edit command. It replaces all occurrences of AText with AReplacement . |
SelectAll | ‘Select all’ edit command. Selects all of the text. |
Undo | ‘Undo’ edit command. Undoes the previous change. |
Unselect | ‘Unselect’ edit command. Unselects everything. |
Events for TWebSyntaxMemo
Event | Description |
---|---|
OnChangeCursor | Event triggered when cursor position has changed. |
OnChangeSelection | Event triggered when text selection has changed. |
OnDragDrop | Event triggered when something is dropped onto the editor. |
OnDragOver | Event triggered when something is dragged over the editor. |