Editing HTML Text
TTMSFNCHTMLEditor opens a dialog with a memo, formatting toolbars, and a live TTMSFNCHTMLText preview. Use it when users should edit HTML-capable text at runtime.
Open the Editor
Set Text before calling Execute. After the dialog is accepted, read Text and assign it to the target control.
TMSFNCHTMLEditor1.Text := TMSFNCHTMLText1.Text;
if TMSFNCHTMLEditor1.Execute = mrOK then
TMSFNCHTMLText1.Text := TMSFNCHTMLEditor1.Text;
Support Images
Assign BitmapContainer when edited text can contain image references. The editor passes the same container to its preview control so image markup resolves while the user edits.
TMSFNCHTMLEditor1.BitmapContainer := TMSFNCBitmapContainer1;
TMSFNCHTMLEditor1.Text := 'Product <b>preview</b><br><img src="logo">';
TMSFNCHTMLEditor1.Execute;
Reuse an Editor Instance
Keep one editor instance when the same form edits multiple HTML text controls. Update Text before each call and apply the returned value to the active target.
procedure TForm1.EditHtmlText(ATextControl: TTMSFNCHTMLText);
begin
TMSFNCHTMLEditor1.Text := ATextControl.Text;
if TMSFNCHTMLEditor1.Execute = mrOK then
ATextControl.Text := TMSFNCHTMLEditor1.Text;
end;
Combining image support and editor reuse for multiple controls
Assign one BitmapContainer to the editor and reuse the same instance across several HTML text controls on the form:
procedure TForm1.EditHTML(ATarget: TTMSFNCHTMLText);
begin
TMSFNCHTMLEditor1.BitmapContainer := TMSFNCBitmapContainer1;
TMSFNCHTMLEditor1.Text := ATarget.Text;
if TMSFNCHTMLEditor1.Execute then
ATarget.Text := TMSFNCHTMLEditor1.Text;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EditHTML(TMSFNCHTMLText1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
EditHTML(TMSFNCHTMLText2);
end;