5

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?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Steve
  • 640
  • 1
  • 7
  • 19
  • 1
    both Andreas and David were right but David was the first to see my mistake that was messing up my text. Thanks to both. – Steve Nov 30 '11 at 21:56

3 Answers3

12

To obtain the unformatted text, simply use RichEdit1.Text.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • +1 'cos you were quicker. I didn't have the courage of my convictions and had to check! – David Heffernan Nov 30 '11 at 21:29
  • 1
    @David: But I checked it too! – Andreas Rejbrand Nov 30 '11 at 21:29
  • The Text returned the text and all the formatting data as text. I dont want the formatting data. – Steve Nov 30 '11 at 21:33
  • @Steve: That does not happen to me. What Delphi version are you using? Does the same thing happen if you open a new project and drop a single `TRichEdit` onto the main form? – Andreas Rejbrand Nov 30 '11 at 21:36
  • `Text` returns the visible text. You can see the formatting data in your rich edit if you look.# – David Heffernan Nov 30 '11 at 21:37
  • The database contains the formatting. It is loaded into my control using the text. (richedit.text := TheDataString;) it displays as formatted. Now I want to read it out as text only it still contains the formatting. – Steve Nov 30 '11 at 21:42
  • 2
    @Steve: Maybe you should have mentioned that 'detail' from the beginning? – Andreas Rejbrand Nov 30 '11 at 21:43
  • What do you expect if you do `richedit.text := TheDataString`. That puts the formatting in as plain text and so it comes right back at you when you pull it out. Put it into a memory stream (or a blob stream from DB) and use `RichEdit.LoadFromStream()`. – David Heffernan Nov 30 '11 at 21:43
  • 2
    You cannot use the `TRichEdit.Text` property to load RTF formatting. To load RTF correctly, you must use one of the `TRichEdit.Lines.LoadFrom...()` methods with the `TRichEdit.PlainText` property set to False. Then you can use the `TRichEdit.Text` property to retreive the unformatted text. – Remy Lebeau Nov 30 '11 at 21:44
11

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you both. That did it. I knew it must be somthing like that but since it has been working fine loading directly into text I didn't think to re-look at that. – Steve Nov 30 '11 at 21:55
2

i use this way to get unformatted text

procedure TMainForm.O1Click(Sender: TObject);

begin

if sOpenDialog1.Execute then

sRichEdit1.Lines.LoadFromFile(sOpenDialog1.FileName);

sMemo1.Text := sRichEdit1.Text;

sRichEdit1.Clear;

sRichEdit1.Text := sMemo1.Text;

for save file you have to choices save as .txt the text still in memo but all change you made will be in richedit only so you have to move text to memo after done all your changes then save it from memo

save as .rtf just save it from richedit I hope thats help you