Author: Maarten de Haan
If you work with a RichEdit and you set the property PlainText to True, then you
can get formatted text into your RichEdit when you use:
RichEdit1.PasteFromClipboard;
Because you set PlainText to True, you are not able to "unformat" this text again.
A work around for this problem is using the procedure below. (This is a well known
bug! On the site of Borland you'll find another - but very complicated - work
around at: http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=13345)
Answer:
1 2 //----------------------------------------------------------------------3 procedure TForm1.EditPasteClick(Sender: TObject);
4 5 var6 h: THandle;
7 pchP: PChar;
8 asS0: ANSIstring;
9 10 begin11 ClipBoard.Open;
12 try13 h := Clipboard.GetAsHandle(CF_TEXT);
14 pchP := GlobalLock(h);
15 asS0 := StrPas(pchP);
16 GlobalUnlock(h);
17 finally18 Clipboard.Close;
19 end;
20 if Length(asS0) > 0 then21 RichEdit1.SelText := asS0; // Copy in where the cursor / caret is.22 end;
23 //----------------------------------------------------------------------