Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to retrieve clipboard data in RTF tokens Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Retrieve clipboard data in RTF tokens 06-Feb-03
Category
VCL-General
Language
Delphi 2.x
Views
123
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

I'm trying to retrieve clipboard data in RTF tokens, and I can't figure out how to 
do it. Here's the scenario: 1. Create rich text in (eg) WordPad, including bold, 
italics etc., 2. Copy that to the clipboard., 3. Paste it into a TRichEdit. The 
pasted data includes all the formatting info. However, if I try to get that data 
off the clipboard myself, using Clipboard.AsText, or getting a handle to it with 
CF_TEXT, what I get is plain text, minus the formatting. It seems to me there 
should be a way to get RTF tokens from the clipboard, but neither the Delphi docs 
nor the MS documentation lists any format that could include rich text. There is no 
such format as CF_RICHTEXT. Anybody know how I can do this? Am I completely wrong 
to assume that RTF tokens are even being passed through the clipboard in the above 
scenario?

Answer:

1   uses
2     RichEdit;
3   
4   function GetRawRTFFromClipboard: string;
5   var
6     H: THandle;
7     TextPtr: PChar;
8     CurrentFormat: Integer;
9     NameLen: DWord;
10    NameStr: string;
11  begin
12    Result := '';
13    ClipBoard.Open;
14    try
15      CurrentFormat := EnumClipboardFormats(0);
16      while CurrentFormat <> 0 do
17      begin
18        NameLen := 1024;
19        SetLength(NameStr, NameLen);
20        NameLen := GetClipboardFormatName(CurrentFormat, PChar(NameStr), NameLen);
21        SetLength(NameStr, NameLen);
22        if CompareText(NameStr, CF_RTF) = 0 then
23          Break;
24        CurrentFormat := EnumClipboardFormats(CurrentFormat);
25      end;
26      if CurrentFormat = 0 then
27        raise Exception.Create('Data on clipboard is not RTF');
28      H := Clipboard.GetAsHandle(CurrentFormat);
29      TextPtr := GlobalLock(H);
30      Result := StrPas(TextPtr);
31      GlobalUnlock(H);
32    finally
33      Clipboard.Close;
34    end;
35  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC