Using Clipboard to copy and paste rtf

Hello,

I'm using Delphi 7 to try and copy RTF information to the clipboard.  I have the information in a TMemoField.  Here's what I currently have:

        mField := TMemoField(dm.tblOptions.FieldByName('QDes')); // points to field in my db
        Clipboard.AsText := mField.AsString;

Unfortunately, when I paste this into Word, it pastes all the strings and the rtf formatting characters, which is not good.

How can I do the above with rtf content?

Thanks!
LVL 3
light_bulbAsked:
Who is Participating?
 
kretzschmarCommented:
of course you have first to render the content

easiest is to assign the content into a hidden TRichEdit,
and copy from there to the clipboard

meikl ;-)
0
 
light_bulbAuthor Commented:
Here's what I came up with that works:

        mField := TMemoField(dm.tblOptions.FieldByName('QDes')); // point to the proper field in my db
        CF_RTF := RegisterClipboardFormat('Rich Text Format');  //register rtf format with clipboard

        //allocate memory for rtf description and copy it to clipboard
        With Clipboard Do
        Begin
            MemHandle := GlobalAlloc(GHND Or GMEM_SHARE, StrLen(PChar(mField.AsString)) + 1);
            If MemHandle <> 0 Then
            Begin
                StrCopy(GlobalLock(MemHandle), PChar(mField.AsString));
                GlobalUnlock(MemHandle);
                Open;
                Try
                    SetAsHandle(CF_RTF, MemHandle);
                Finally
                    Close;
                End;
            End
            Else
                MessageDlg('Error while allocating memory!', mtError, [mbOK], 0);
        End;
0
 
kretzschmarCommented:
well done, light_bulb :-))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.