ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → Delphi
uses
ComCtrls;
function RichTextToPlainText(richText: string): string;
var
RichEdit1: TRichEdit;
ss: TStringStream;
begin
if Copy(richText, 1, 5) <> '{\rtf' then
begin
result := richText;
exit;
end;
RichEdit1 := TRichEdit.Create(Application.MainForm);
try
// It doesn't work if Visible=true or Parent=nil ...
RichEdit1.Width := 0;
RichEdit1.Height := 0;
RichEdit1.Parent := Application.MainForm;
// RichEdit1.Text := richText;
ss := TStringStream.Create(richtext);
RichEdit1.Lines.LoadFromStream(ss);
ss.Free;
RichEdit1.PlainText := true;
result := Trim(RichEdit1.Text);
finally
FreeAndNil(RichEdit1);
end;
if Copy(result, 1, 5) = '{\rtf' then
begin
ShowMessage('RTF-To-Text failed!');
end;
end;
Daniel Marschall
ViaThinkSoft Co-Founder
ViaThinkSoft Co-Founder