delphirichedit

Getting unformatted text from RichEdit


I have a Richedit that allows my users to format and view error messages that display within my application.

I now need to be able to export the text only (no formatting) out to another database that their trouble-ticket system uses.

I have tried all the combinations of PlainText I can think of and I always still get the rtf formatting.

How can I get the text only?


Solution

  • Answering the direct question that you asked, the Text property is precisely what you are looking for. For some reason it doesn't show up in the TRichEdit documentation, but it is inherited from TCustomEdit.

    It sounds to me (following comments to Andreas' answer) as though what you really need to do it as follows:

    1. Pull the RTF from the DB into a memory stream or perhaps a blob stream.
    2. Call RichEdit.LoadFromStream passing that stream, making sure PlainText is False.
    3. Then read RichEdit.Text to get the unformatted text.

    At the moment you are simply putting the RTF into the control as plain text. You need to put it into the control as rich text, and for that you need LoadFromStream.