Getting Unformatted Text From RichEdit

I have Richedit that allows my users to format and view error messages that appear in my application.

Now I need to be able to export only text (without formatting) to another database that the system for eliminating them uses.

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

How can I get only text?

+4
source share
3 answers

Answering the direct question that you asked, the Text property is exactly what you are looking for. For some reason, it does not appear in the TRichEdit documentation, but is inherited from TCustomEdit .

It seems to me (after comments on Andreas's answer), as if you really need to do this as follows:

  • Pull the RTF from the database into the memory stream or possibly a blob stream.
  • A call to RichEdit.LoadFromStream passing this stream, make sure PlainText False .
  • Then read RichEdit.Text to get unformatted text.

At the moment, you simply put the RTF in the control as plain text. You need to include it as rich text, and for this you need LoadFromStream .

+10
source

To get unformatted text, just use RichEdit1.Text .

+10
source

I use this method to get plain 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; 

to save the file you have the choice to save as .txt the text is still in the memo, but all the changes you made will only be in richedit, so you will need to move the text to the memo after all your changes are done, and then save it from the memo

save as .rtf just save it from richedit Hope this helps you.

+2
source

Source: https://habr.com/ru/post/1383990/


All Articles