MagicFrisbee
Programmer
For a few versions of Delphi, I've been able to move rich text format code into Word using the following code, where ocxWordDoc is a TWordComponent on the form:
Now, before I get all jumped over, I realize it's a Unicode issue. I've completely read Chapter 2 of Cantu's 2009 Handbook and I'm still stuck. None of my fixes produce the correct output in the Word document. It might be because of my failed understanding of clipboard formats in Delphi. Can someone help me?
Also, I'd rather NOT use the Clipboard if I can help it, but the rest of the Word document is normal text, and this Rich Text comes from a database.
GIS Programmer
City of Orem, UT
Code:
var
sRTF: String;
lRTFFormat, hGlobal: THandle;
lpString: Pointer;
begin
{...}
sRTF := qryComments.FieldByName( 'DPCOMMENT' ).AsString;
lRTFFormat := RegisterClipboardFormat( CF_RTF );
hGlobal := GlobalAlloc( GMEM_MOVEABLE or GMEM_DDESHARE,
Length( sRTF ) + 1 );
lpString := GlobalLock( hGlobal );
StrCopy( lpString, PAnsiChar(sRTF) );
GlobalUnlock( hGlobal );
Clipboard.Open;
Clipboard.SetAsHandle( lRTFFormat, hGlobal );
Clipboard.Close;
ocxWordDoc.Paragraphs.Last.Range.Paste;
Now, before I get all jumped over, I realize it's a Unicode issue. I've completely read Chapter 2 of Cantu's 2009 Handbook and I'm still stuck. None of my fixes produce the correct output in the Word document. It might be because of my failed understanding of clipboard formats in Delphi. Can someone help me?
Also, I'd rather NOT use the Clipboard if I can help it, but the rest of the Word document is normal text, and this Rich Text comes from a database.
GIS Programmer
City of Orem, UT