Action toolbars
The clipboard, insert and file I/O toolbars expose document actions rather than
formatting. Like the formatting bars they bind through Control and carry an
Options set, but their events are the focus: clipboard actions usually run
against the editor automatically, while insert and file I/O actions typically
need your application to supply the image, link target, or file name.
Clipboard toolbar
TTMSFNCClipboardToolBar.Options is a set of TTMSFNCClipboardToolBarOption
values (etoCut, etoCopy, etoPaste, etoUndo, etoRedo). The matching
OnCut, OnCopy, OnPaste, OnUndo and OnRedo events fire after the action
runs against the connected editor.
// A clipboard toolbar: cut, copy, paste, undo and redo. Limit the visible
// buttons with Options and react with the per-action events.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCClipboardToolBar1.Control := TMSFNCRichEditor1;
TMSFNCClipboardToolBar1.Options := [etoCut, etoCopy, etoPaste, etoUndo, etoRedo];
end;
procedure TForm1.TMSFNCClipboardToolBar1Paste(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Pasted from clipboard';
end;
// A clipboard toolbar: cut, copy, paste, undo and redo. Limit the visible
// buttons with Options and react with the per-action events.
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMSFNCClipboardToolBar1->Control = TMSFNCRichEditor1;
TMSFNCClipboardToolBar1->Options = TTMSFNCClipboardToolBarOptions()
<< TTMSFNCClipboardToolBarOption::etoCut << TTMSFNCClipboardToolBarOption::etoCopy
<< TTMSFNCClipboardToolBarOption::etoPaste << TTMSFNCClipboardToolBarOption::etoUndo
<< TTMSFNCClipboardToolBarOption::etoRedo;
}
void __fastcall TForm1::TMSFNCClipboardToolBar1Paste(TObject *Sender)
{
StatusLabel->Text = "Pasted from clipboard";
}
Insert toolbar
TTMSFNCInsertToolBar.Options is a set of TTMSFNCInsertToolBarOption values
(ftiImage, ftiHyperlink). Handle OnInsertBitmap and OnInsertHyperlink to
present your own file or link dialog, since the toolbar cannot know the source.
// An insert toolbar: image and hyperlink buttons. These actions typically need
// the application to supply the file name or URL, so handle their events.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCInsertToolBar1.Control := TMSFNCRichEditor1;
TMSFNCInsertToolBar1.Options := [ftiImage, ftiHyperlink];
end;
procedure TForm1.TMSFNCInsertToolBar1InsertHyperlink(Sender: TObject);
begin
// Show your own dialog and insert the link into the bound editor.
ShowMessage('Insert hyperlink');
end;
procedure TForm1.TMSFNCInsertToolBar1InsertBitmap(Sender: TObject);
begin
ShowMessage('Insert image');
end;
// An insert toolbar: image and hyperlink buttons. These actions typically need
// the application to supply the file name or URL, so handle their events.
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMSFNCInsertToolBar1->Control = TMSFNCRichEditor1;
TMSFNCInsertToolBar1->Options = TTMSFNCInsertToolBarOptions()
<< TTMSFNCInsertToolBarOption::ftiImage << TTMSFNCInsertToolBarOption::ftiHyperlink;
}
void __fastcall TForm1::TMSFNCInsertToolBar1InsertHyperlink(TObject *Sender)
{
// Show your own dialog and insert the link into the bound editor.
ShowMessage("Insert hyperlink");
}
void __fastcall TForm1::TMSFNCInsertToolBar1InsertBitmap(TObject *Sender)
{
ShowMessage("Insert image");
}
File I/O toolbar
TTMSFNCFileIOToolBar.Options is a set of TTMSFNCFileIOToolBarOption values
(itoOpenFile, itoSaveFile). Handle OnOpenFile and OnSaveFile to choose a
path or run your own open/save flow.
// A file I/O toolbar: open and save buttons for the bound editor's document.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCFileIOToolBar1.Control := TMSFNCRichEditor1;
TMSFNCFileIOToolBar1.Options := [itoOpenFile, itoSaveFile];
end;
procedure TForm1.TMSFNCFileIOToolBar1OpenFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Document opened';
end;
procedure TForm1.TMSFNCFileIOToolBar1SaveFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Document saved';
end;
// A file I/O toolbar: open and save buttons for the bound editor's document.
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMSFNCFileIOToolBar1->Control = TMSFNCRichEditor1;
TMSFNCFileIOToolBar1->Options = TTMSFNCFileIOToolBarOptions()
<< TTMSFNCFileIOToolBarOption::itoOpenFile << TTMSFNCFileIOToolBarOption::itoSaveFile;
}
void __fastcall TForm1::TMSFNCFileIOToolBar1OpenFile(TObject *Sender)
{
StatusLabel->Text = "Document opened";
}
void __fastcall TForm1::TMSFNCFileIOToolBar1SaveFile(TObject *Sender)
{
StatusLabel->Text = "Document saved";
}
Combining the action toolbars
Putting it together — clipboard, insert and file I/O bars on one editor, each
with its own Options, forming a complete action strip:
// Clipboard, insert and file I/O toolbars sharing a single editor. Each keeps
// its own Options so the three bars together form a complete action strip.
procedure TForm1.FormCreate(Sender: TObject);
begin
TMSFNCClipboardToolBar1.Control := TMSFNCRichEditor1;
TMSFNCInsertToolBar1.Control := TMSFNCRichEditor1;
TMSFNCFileIOToolBar1.Control := TMSFNCRichEditor1;
TMSFNCClipboardToolBar1.Options := [etoCut, etoCopy, etoPaste, etoUndo, etoRedo];
TMSFNCInsertToolBar1.Options := [ftiImage, ftiHyperlink];
TMSFNCFileIOToolBar1.Options := [itoOpenFile, itoSaveFile];
end;
procedure TForm1.TMSFNCInsertToolBar1InsertHyperlink(Sender: TObject);
begin
ShowMessage('Insert hyperlink');
end;
procedure TForm1.TMSFNCFileIOToolBar1SaveFile(Sender: TObject);
begin
StatusBar1.Panels.Items[0].Text := 'Saved';
end;
// Clipboard, insert and file I/O toolbars sharing a single editor. Each keeps
// its own Options so the three bars together form a complete action strip.
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TMSFNCClipboardToolBar1->Control = TMSFNCRichEditor1;
TMSFNCInsertToolBar1->Control = TMSFNCRichEditor1;
TMSFNCFileIOToolBar1->Control = TMSFNCRichEditor1;
TMSFNCClipboardToolBar1->Options = TTMSFNCClipboardToolBarOptions()
<< TTMSFNCClipboardToolBarOption::etoCut << TTMSFNCClipboardToolBarOption::etoCopy
<< TTMSFNCClipboardToolBarOption::etoPaste << TTMSFNCClipboardToolBarOption::etoUndo
<< TTMSFNCClipboardToolBarOption::etoRedo;
TMSFNCInsertToolBar1->Options = TTMSFNCInsertToolBarOptions()
<< TTMSFNCInsertToolBarOption::ftiImage << TTMSFNCInsertToolBarOption::ftiHyperlink;
TMSFNCFileIOToolBar1->Options = TTMSFNCFileIOToolBarOptions()
<< TTMSFNCFileIOToolBarOption::itoOpenFile << TTMSFNCFileIOToolBarOption::itoSaveFile;
}
void __fastcall TForm1::TMSFNCInsertToolBar1InsertHyperlink(TObject *Sender)
{
ShowMessage("Insert hyperlink");
}
void __fastcall TForm1::TMSFNCFileIOToolBar1SaveFile(TObject *Sender)
{
StatusLabel->Text = "Saved";
}
Common mistakes
- Expecting insert/file actions to work without an event handler. The toolbar
raises
OnInsertBitmap/OnOpenFileetc.; your code supplies the data. - Leaving undo/redo enabled on a control that does not support them. Trim the
clipboard
Optionsto the actions the bound editor actually offers.