开发者

Get richtext from a richedit in Delphi

开发者 https://www.devze.com 2023-01-14 03:13 出处:网络
Is there a way to get the RTF data from a richedit without using savetostream as in strStream := TStringStream.Create(\'\') ;

Is there a way to get the RTF data from a richedit without using savetostream as in

strStream := TStringStream.Create('') ;
try
  RichEdit.Lines.SaveToStream(strStream);
  Text := strStream.Da开发者_如何转开发taString;
  strStream.CleanupInstance;
finally
  strStream.Free


Tim the only way to get the RTF data from an RichEdit control is using a Stream because the windows message (EM_STREAMOUT) wich retrieve the RTF Data require a EditStreamCallback structure, this is the way used by windows to transfer rtf data into or out of a richedit control.

So you can use your own sample code, or implement the call to the windows message EM_STREAMOUT.


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;

I can attest deviation from the pattern results in frustration....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号