[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1934
  • Last Modified:

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!
0
light_bulb
Asked:
light_bulb
  • 2
1 Solution
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now