I'm trying to stop nested tables in my TDBRichViewEdit.
Im using the following to test if a user is trying to INSERT a table while currently inside a table.
if (LetterRichViewEdit->InplaceEditor == NULL)
That works fine, but what about pasting? How can I stop a user pasting a table inside another table.
Basically any form of nested tables must be disallowed as the FastReport RichText object can't display nested tables and instead just shows the raw RTF instead of the RichEdit output.
Unfortunately, there is no such property.
The most universal way is using OnPaste event. If InplaceEdit!=NULL, then paste into a hidden editor, remove tables in it, save to stream (SaveRVFToStream), insert in the main editor (InsertRVFFromStreamEd), set DoDefault parameter = False.
void __fastcall TMailEditor::LetterRichViewEditPaste(TCustomRichViewEdit *Sender, bool &DoDefault)
{
// If inside a table when pasting, run the ConvertAllTablesToText function to stip the table.
if (LetterRichViewEdit->InplaceEditor != NULL)
{
DoDefault = false;
TRichViewEdit *rvTemp = new TRichViewEdit((TComponent*)NULL);
rvTemp->Style = MailRVStyle;
rvTemp->Parent = MailEditor;
rvTemp->Paste();
ConvertAllTablesToText(rvTemp->RVData, true);
rvTemp->Format();
TMemoryStream *MemStream = new TMemoryStream();
rvTemp->SaveRVFToStream(MemStream, false);
MemStream->Position = 0;
LetterRichViewEdit->InsertRVFFromStreamEd(MemStream);// LoadRVFFromStream(MemStream);
LetterRichViewEdit->Format();
delete rvTemp, MemStream;
MessageDlg("You tried to paste a table inside another table,\nthis is not allowed. Only the table contents\nhas been copied!", mtWarning, TMsgDlgButtons() << mbOK, 0);
}
}
//---------------------------------------------------------------------------