TTMSFNCWXHTMLMemo
Edit HTML directly with the TTMSFNCWXHTMLMemo
component. It has an optional embedded format
toolbar or can be used with external toolbar. Programmatic access to all formatting capabilities is
available. Content is loaded and saved directly as HTML. It uses the summernote JavaScript library.
Load and save HTML content
There are 2 ways to load some content into the TTMSFNCWXHTMLMemo
.
The first way is use the LoadHTMLContent(AHTMLText: string)
method to load an HTML string into
the editor.
procedure TForm1.Button1Click(Sender: TObject);
begin
TMSFNCWXHTMLMemo1.LoadHtmlContent('<b>Bold text</b>');
end;
HTML TStrings
property and use the loading mechanisms
that are exposed through TStrings
or set the TStrings.Text
property. This method also applies to
saving the contents.
procedure TForm1.Button1Click(Sender: TObject);
begin
//Load from file:
TMSFNCWXHTMLMemo1.HTML.LoadFromFile('path\to\file');
//Alternatively assign the Text property:
TMSFNCWXHTMLMemo1.HTML.Text := '<b>Bold text</b>';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TMSFNCWXHTMLMemo1.HTML.SaveToFile('path\to\file');
end;
Formatting
The TTMSFNCWXHTMLMemo
is a WYSWYG editor. Via toolbar interaction the text can be formatted.
However it’s not required to depend on the toolbar and the formatting is possible through exposed
methods. This way the toolbar can be disabled and the TTMSFNCWXHTMLMemo
formatting can be
done through custom toolbars.
The following methods are available:
- ResetContent
- Undo
- Redo
- ToggleCodeview
- TextBold
- TextItalic
- TextUnderline
- TextStrikeThrough
- RemoveFormat
- FormatToParagraphs
- Indent
- Outdent
- InsertList(AOrdered: Boolean)
- InsertParagraph
- JustifyLeft
- JustifyRight
- JustifyCenter
- JustifyFull
- SetLineHeight(ALineHeight: Integer)
- SetFontSize(AFontSize: Integer)
- InsertText(AText: string)
- SetFontName(AFontName: string)
Toolbar
The toolbar can be disabled by setting TTMSFNCWXHTMLMemo.Toolbar.Visible
to False.
It is also configurable which buttons should be visible in the toolbar. Disable or enable the buttons
through the TTMSFNCWXHTMLMemo.Toolbar.Buttons
property. By default all buttons are set to
enabled:
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCWXHTMLMemo1.BeginUpdate;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtColor := False;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtClear := False;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtStrikeThrough := False;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtUnderline := False;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtBold := False;
TMSFNCWXHTMLMemo1.Toolbar.Buttons.FontStyle.BtItalic := False;
TMSFNCWXHTMLMemo1.EndUpdate;
end;