Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 374
Steve Avatar asked Nov 30 '11 21:11

Steve


3 Answers

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

like image 142
Andreas Rejbrand Avatar answered Oct 13 '22 08:10

Andreas Rejbrand


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.

like image 29
David Heffernan Avatar answered Oct 13 '22 09:10

David Heffernan


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

like image 20
MasterMan82 Avatar answered Oct 13 '22 10:10

MasterMan82