Getting unformatted text from RichEdit
Asked Answered
A

3

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?

Antietam answered 30/11, 2011 at 21:21 Comment(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.Antietam
P
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.

Petree answered 30/11, 2011 at 21:27 Comment(1)
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.Antietam
C
13

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

Curst answered 30/11, 2011 at 21:26 Comment(9)
+1 'cos you were quicker. I didn't have the courage of my convictions and had to check!Petree
@David: But I checked it too!Curst
The Text returned the text and all the formatting data as text. I dont want the formatting data.Antietam
@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?Curst
Text returns the visible text. You can see the formatting data in your rich edit if you look.#Petree
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.Antietam
@Steve: Maybe you should have mentioned that 'detail' from the beginning?Curst
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().Petree
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.Tight
P
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.

Petree answered 30/11, 2011 at 21:27 Comment(1)
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.Antietam
B
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

Berne answered 1/7, 2013 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.