Skip to main content
Table of Contents

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.

Create an HTML EditorPascalC++
TMSFNCHTMLEditor1.Text := TMSFNCHTMLText1.Text;

if TMSFNCHTMLEditor1.Execute = mrOK then
  TMSFNCHTMLText1.Text := TMSFNCHTMLEditor1.Text;
TMSFNCHTMLEditor1->Text = TMSFNCHTMLText1->Text;

if (TMSFNCHTMLEditor1->Execute() == mrOk)
  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.

Support ImagesPascalC++
TMSFNCHTMLEditor1.BitmapContainer := TMSFNCBitmapContainer1;
TMSFNCHTMLEditor1.Text := 'Product <b>preview</b><br><img src="logo">';
TMSFNCHTMLEditor1.Execute;
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.

Reuse an Editor InstancePascalC++
procedure TForm1.EditHtmlText(ATextControl: TTMSFNCHTMLText);
begin
  TMSFNCHTMLEditor1.Text := ATextControl.Text;

  if TMSFNCHTMLEditor1.Execute = mrOK then
    ATextControl.Text := TMSFNCHTMLEditor1.Text;
end;
void __fastcall TForm1::EditHtmlText(TTMSFNCHTMLText *ATextControl)
{
  TMSFNCHTMLEditor1->Text = ATextControl->Text;

  if (TMSFNCHTMLEditor1->Execute() == mrOk)
    ATextControl->Text = TMSFNCHTMLEditor1->Text;
}

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:

Combining image support and editor reuse for multiple controlsPascalC++
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;
void __fastcall TForm1::EditHTML(TTMSFNCHTMLText *ATarget)
{
  TMSFNCHTMLEditor1->BitmapContainer = TMSFNCBitmapContainer1;
  TMSFNCHTMLEditor1->Text = ATarget->Text;
  if (TMSFNCHTMLEditor1->Execute())
    ATarget->Text = TMSFNCHTMLEditor1->Text;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  EditHTML(TMSFNCHTMLText1);
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  EditHTML(TMSFNCHTMLText2);
}

See Also