将 RTF 文本从数据库加载到 TRichEdit
我目前正在将我们的软件解决方案从 Delphi 7 迁移到 2010。大部分更改都很简单,只剩下少量障碍。
在表单上,我们使用 TRichEdit,它显示从 MSSQL 数据库中的 blob 字段抓取的 rtf 文本。这就是它在 Delphi 7 中的工作方式:
//Get RTF text from Blob field using TADOQuery
rtfStream := sql.CreateBlobStream(sql.FieldByName('rtftext'), BmRead) as TMemoryStream;
//Load into TRichEdit
RichEdit.PlainText := False;
RichEdit.Lines.LoadFromStream(rtfStream);
这将按照 TRichEdit 组件中的预期显示 RTF,但 Delphi 2010 中的相同代码将 RTF 显示为纯文本,每个字符之间带有制表符。我认为这与从 Ansi 到 Unicode 的更改有很大关系,但我没有运气纠正这个问题。
任何帮助使其发挥作用将不胜感激。谢谢
I am currently in the process of migrating our software solution from Delphi 7 to 2010. Mostly the changes have been simple and there are only a small amount of hurdles left to go.
On a form we use a TRichEdit which displayed rtf text grabbed from a blob field in a MSSQL db. This is how it worked in Delphi 7:
//Get RTF text from Blob field using TADOQuery
rtfStream := sql.CreateBlobStream(sql.FieldByName('rtftext'), BmRead) as TMemoryStream;
//Load into TRichEdit
RichEdit.PlainText := False;
RichEdit.Lines.LoadFromStream(rtfStream);
This would display the RTF as expected in the TRichEdit component, but the same code in Delphi 2010 displays the RTF as plain text with tabs between each character. I assume this has a lot to do with the change from Ansi to Unicode, but I haven't had any luck rectifying the problem.
Any help getting this to work would be much appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我想通了。
用于加载 rtf 文本:
用于保存 rtf 文本:
这花了我太长时间才弄清楚:)我想我已经学到了一件事......如果有的话Delphi 2010 中出错,通常与 unicode 有关;)
Okay I figured it out.
For loading the rtf text:
For saving the rtf text:
This took me way too long to figure out :) I guess I have learned one thing though... if something goes wrong in Delphi 2010, its usually related to unicode ;)
当 PlainText 为 False 时,LoadFromStream() 首先尝试加载 RTF 代码,如果失败,则 LoadFromStream() 尝试再次以纯文本形式加载流。所有 Delphi 版本都是如此。随着 Unicode 的引入,我认为 LoadFromStream() 的
EM_STREAMIN
回调处理程序中可能会出现某些问题。我建议您使用调试器进入 LoadFromStream() 的实际源代码,看看到底发生了什么。When PlainText is False, LoadFromStream() first attempts to load the RTF code, and if that fails then LoadFromStream() attempts to load the stream again as plain text. That has always been the case in all Delphi versions. With the introduction of Unicode, I suppose something could have broken in LoadFromStream()'s
EM_STREAMIN
callback handler. I suggest you step into LoadFromStream()'s actual source code with the debugger and see what is really happening.