Get rich text from richedit in Delphi

Is there any way to get RTF data from richedit without using savetostream, as in

strStream := TStringStream.Create('') ;
try
  RichEdit.Lines.SaveToStream(strStream);
  Text := strStream.DataString;
  strStream.CleanupInstance;
finally
  strStream.Free
+3
source share
2 answers

Tim, the only way to get RTF data from a RichEdit control is to use Stream, because the Windows ( EM_STREAMOUT) message , which requires a structure to receive RTF data EditStreamCallback, is the way Windows uses to transfer rtf data to or from a richedit control.

Thus, you can use your own sample code or implement a message box call EM_STREAMOUT.

+4
source
function RichTextToStr(red : TRichEdit) : string;

var   ss : TStringStream;

begin
  ss := TStringStream.Create('');

  try
    red.Lines.SaveToStream(ss);
    Result := ss.DataString;
  finally
    ss.Free;
  end;
end;

procedure CopyRTF(redFrom,redTo : TRichEdit);

var   s : TMemoryStream;

begin
  s := TMemoryStream.Create;

  try
    redFrom.Lines.SaveToStream(s);
    s.Position := 0;
    redTo.Lines.LoadFromStream(s);
  finally
    s.Free;
  end;
end;

....

+2

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


All Articles