Previously after calling VirtualStringGrid -> CopyToClipBoard
, I could paste the grid as tabbed text in notepad or as a fully formatted grid (headers and colour and borders) when pasting into Excel or Outlook.
However, I'm experiencing issues with CopyToClipboard
since I moved from Embarcadero XE8 to RAD Seattle with VirtualTreeView V6.2 : I only can paste as text if the target application is some kind of text editor. Pasting to any kind of 'rich' application that would accept RTF or html results in error.
I've tried to call the ContentToXXX
methods (see code below) text is exported fine. Html is exported, but the resulting Data2Export
string contains the whole code on an html page and cannot be pasted to Outlook, for instance.
Any call to ContentToRTF
results in a crash.
I googled for this kind of issue but I did not find anything quite relevant.
void __fastcall TForm::ExportGrid( void )
{
// old code that used to work fine
// VST->CopyToClipboard();
Virtualtrees::TVSTTextSourceType exportSrcType = tstAll;
OpenClipboard( Handle );
EmptyClipboard();
std::string Data2Export = "";
HGLOBAL hg;
// tabbed text
Data2Export = AnsiString( VST->ContentToText( exportSrcType, "\t" ) ).c_str();
hg = GlobalAlloc( GMEM_MOVEABLE, Data2Export.size() + 1 );
if ( !hg )
{
CloseClipboard();
return;
}
memcpy( GlobalLock( hg ), Data2Export.c_str(), Data2Export.size() + 1 );
GlobalUnlock( hg );
SetClipboardData( CF_TEXT, hg );
GlobalFree( hg );
// html
Data2Export = AnsiString( VST->ContentToHTML( exportSrcType ) ).c_str();
hg = GlobalAlloc( GMEM_MOVEABLE, Data2Export.size() + 1 );
if ( !hg )
{
CloseClipboard();
return;
}
memcpy( GlobalLock( hg ), Data2Export.c_str(), Data2Export.size() + 1 );
GlobalUnlock( hg );
SetClipboardData( CF_HTML, hg );
GlobalFree( hg );
// RTF
Data2Export = AnsiString( VST->ContentToRTF( exportSrcType ).c_str() ).c_str();
hg = GlobalAlloc( GMEM_MOVEABLE, Data2Export.size() + 1 );
if ( !hg )
{
CloseClipboard();
return;
}
memcpy( GlobalLock( hg ), Data2Export.c_str(), Data2Export.size() + 1 );
GlobalUnlock( hg );
SetClipboardData( CF_TEXT, hg );
GlobalFree( hg );
CloseClipboard();
}
Any idea of how to solve or workaround this issue?
Something wrong with the code?
PD: the dev platform are Win8 and Win10 and the VirtualStringTree ClipboardFormats are all set to true.