从Delphi中的richedit获取richtext
有没有一种方法可以从richedit中获取RTF数据而不使用savetostream,如中所示从Delphi中的richedit获取richtext,delphi,delphi-2007,richedit,Delphi,Delphi 2007,Richedit,有没有一种方法可以从richedit中获取RTF数据而不使用savetostream,如中所示 strStream := TStringStream.Create('') ; try RichEdit.Lines.SaveToStream(strStream); Text := strStream.DataString; strStream.CleanupInstance; finally strStream.Free Tim从RichEdit控件获取RTF数据的唯一方法是使用
strStream := TStringStream.Create('') ;
try
RichEdit.Lines.SaveToStream(strStream);
Text := strStream.DataString;
strStream.CleanupInstance;
finally
strStream.Free
Tim从RichEdit控件获取RTF数据的唯一方法是使用流,因为检索RTF数据的windows消息()需要一个结构,这是windows将RTF数据传输到RichEdit控件或从RichEdit控件传出的方法 因此,您可以使用自己的示例代码,或者实现对windows消息的调用
我可以证明与模式的偏差会导致挫折….不要显式调用
CleanupInstance
,它是在流被销毁时调用的。换句话说,使用Free()
而不是CleanupInstance()
。如果SaveToStream()
引发异常,您应该使用try/finally
。SaveToStream()方法在内部使用EM\u STREAMOUT
。为什么不使用SaveToStream()
?
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;