Best way to stop nested tables.

General TRichView support forum. Please post your questions here
Post Reply
vizualweb
Posts: 10
Joined: Tue Jul 17, 2012 1:59 am
Location: Australia

Best way to stop nested tables.

Post by vizualweb »

Hi All,

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.

Cheers!

:D
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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.

To remove tables in a hidden editor, you can use this procedure: http://www.trichview.com/forums/viewtop ... =581#16214
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Besides, exclude RTF and RVF from AcceptDragDropFormat, because there is no event like OnPaste for drag&drop.
vizualweb
Posts: 10
Joined: Tue Jul 17, 2012 1:59 am
Location: Australia

Post by vizualweb »

Thanks Sergey,

The ConvertAllTablesToText worked a treat (I'm using C++ Builder XE, but just added the procedure to a .pas unit and used it from there.

Also the OnPaste worked perfectly (just incase its useful for others).

Code: Select all

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);
	}
}
//---------------------------------------------------------------------------

Post Reply