简体   繁体   English

Delphi 7,TRichedit,被RTF编码困住

[英]Delphi 7, TRichedit, Stuck by RTF Coding

I am giving you brief idea about this issue. 我正在简要介绍一下这个问题。

  1. Retrieving (id,name) fields records from database into list box. 从数据库中检索(id,name)字段记录到列表框中。
  2. Select any record from list. 从列表中选择任何记录。
  3. Display Notes (Blob type) into rich edit box for selected id. 将Notes(Blob类型)显示在所选id的富编辑框中。
  4. Except two records all are fine. 除了两个记录都很好。
  5. Both two records has thousands of lines of records into database. 两条记录都有数千行记录到数据库中。 Notes : [ It comes from notes being pasted from word or outlook with certain rtf formatting codes. 注意:[它来自于使用某些rtf格式代码从word或outlook粘贴的注释。 The ones that seem to cause the "sticky note" is where a /f0protect (or something very similar to that) is on the coding. 似乎导致“粘滞便笺”的那些是编码上的/ f0protect(或与其非常相似的东西)。 All of the ones that cause problems have this somewhere in the notes pages. 导致问题的所有问题都在注释页面中的某处。 The solution is to open the base table record and find the record and display the notes field. 解决方案是打开基表记录并查找记录并显示备注字段。 Cut/Remove the notes from the base table record and paste them into Word or Notepad (depending on volume). 剪切/删除基表记录中的注释并将其粘贴到Word或记事本中(取决于卷)。 Do lots of Find & Replace on the rtf coding. 在rtf编码上进行大量查找和替换。 And re-copy the notes back into the base table record. 然后将注释重新复制回基表记录中。 ] ]

  6. Displaying data correctly into rich edit. 正确显示数据到富编辑。

  7. Afterward that records, application failed to load another notes into rich edit by selecting another records from list box. 之后记录,应用程序无法通过从列表框中选择其他记录将其他备注加载到富编辑中。
  8. Giving a error sound internally. 在内部发出错误声音。
  9. Doesn't throwing any error or exception. 不抛出任何错误或异常。

I have three things in my mind for this problem. 对于这个问题,我脑子里有三件事。 1. Problem could be with RTF Codes. 1.问题可能出在RTF代码上。 2. Buffer or memory. 2.缓冲区或内存。 3. TRichEdit control. 3. TRichEdit控制。

I hope this explanation would be helpful to help me. 我希望这个解释对我有所帮助。

Thanks in advance for help. 在此先感谢您的帮助。

First of all I'm going to rephrase your question, because in it's current incarnation (numbered list) it isn't easy to answer. 首先,我要重新解释你的问题,因为在它的当前化身(编号列表)中,它不容易回答。 I considered actually editing your question, but that might have been too harsh. 我考虑过编辑你的问题,但这可能太苛刻了。 I'm only doing this because you're new to the site. 我只是这样做,因为你是网站的新手。 If you weren't new I'd simply put in an comment asking "What's the question?" 如果你不是新人我会简单地发表评论,询问“这是什么问题?”

This is what I think the question should have looked like: 这就是我认为这个问题应该是这样的:


TRichEdit miss-behaving with some specific RTF TRichEdit错过了一些特定的RTF

I'm generating some RTF based on data from a database and loading it into an TRichEdit control. 我正在根据数据库中的数据生成一些RTF并将其加载到TRichEdit控件中。 Most of the time it works fine, but in a couple of cases the resulting RTF causes the TRichEdit to miss-behave: It displays the RTF just fine, but when moving to a new record, the TRichEdit simply refuses to load new text! 大部分时间它工作正常,但在一些情况下,生成的RTF导致TRichEdit错过行为:它显示RTF就好了,但是当移动到新记录时,TRichEdit只是拒绝加载新文本! It doesn't throw an exception, but an error-beep is heard from the computer. 它不会抛出异常,但会从计算机中听到错误的哔声。

Some background: The text that's loaded in the TRichEdit is thousand of lines long, not something that can be easily attached to this message. 一些背景:在TRichEdit中加载的文本长达数千行,而不是可以轻松附加到此消息的内容。 This RTF is built from smaller bits of RTF, copy-pasted from Microsoft Outlook or Microsoft Word. 此RTF由较小的RTF位构建,从Microsoft Outlook或Microsoft Word复制粘贴。 Apparently the error happens when /f0protect (or something very similar to that) is found in the bits of RTF that came from Outlook or Word. 显然,当在来自Outlook或Word的RTF位中找到/f0protect (或与此类似的东西)时会发生错误。 Going into the database and removing those markups fixes the problem, but I need a better solution. 进入数据库并删除这些标记可以解决问题,但我需要一个更好的解决方案。

I'm not sure what the problem might be. 我不确定问题可能是什么。 I'm thinking it's one of: 我在想它是以下之一:

  1. Problem could be with RTF Codes. 问题可能出在RTF代码上。
  2. Buffer or memory. 缓冲区或内存。
  3. TRichEdit control. TRichEdit控制。

And now my answer: 现在我的回答是:

Some background about the RTF format. 关于RTF格式的一些背景知识。 First of all, it's an Microsoft controlled format that's being continuously revised. 首先,它是一种不断修改的Microsoft控制格式。 You can pretty much save any Word document in RTF format, re-load it in Word and have it look the same. 您几乎可以以RTF格式保存任何Word文档,在Word中重新加载它并使其看起来相同。 It doesn't mean you can load any RTF into WordPad and have it look exactly as it did in Word! 这并不意味着您可以将任何RTF加载到写字板中,并使其看起来与在Word中完全一样! Microsoft is too smart to make such a childish mistake. 微软太聪明了,不能犯这么幼稚的错误。 WordPad is just an wrapper around the Microsoft Rich Text Controll (just as TRichEdit). 写字板只是Microsoft Rich Text Controll的包装器(就像TRichEdit一样)。 This implies there are limitations with what TRichEdit can do. 这意味着TRichEdit可以做的事情存在局限性。

Secondly, the RTF format is not context-free: you can't expect to simply append two peaces of RTF and get valid RTF! 其次,RTF格式不是无上下文的:你不能期望简单地附加两个RTF并获得有效的RTF! An RTF document is supposed to start with an header, followed by the document area. RTF文档应该以标题开头,然后是文档区域。 If you append two peaces of RTF you get two headers, and I'm thinking the result is undefined. 如果你追加两个RTF的和平,你得到两个标题,我认为结果是未定义的。

You're probably right, the problem is one of the 3 you mentioned. 你可能是对的,问题是你提到的3个问题之一。 Happily it's easy to test, throw a process of elimination: 令人高兴的是,它很容易测试,抛出一个消除过程:

  1. Buffer or memory: How big is your resulting RTF? 缓冲区或内存:您产生的RTF有多大? Create some equal-length (or larger) RTF from code, making sure it only contains simple RTF. 从代码中创建一些等长(或更大)的RTF,确保它只包含简单的RTF。 Does it miss-behave? 它错过了吗? If so, you ran into some kind of memory limitation, but I doubt it. 如果是这样,你遇到了某种内存限制,但我对此表示怀疑。 None the less it's easy to test! 尽管如此,它很容易测试!

  2. Problem could be with RTF Codes: Very likely! RTF代码可能存在问题:非常可能! You say the problem goes away if you remove those offending tags from the database; 你说如果从数据库中删除那些有问题的标签,问题就会消失; Remove the tags from code in the process of building the big RTF. 在构建大型RTF的过程中从代码中删除标签。 If you end up with a long list of tags that need removing, maybe you need to do it the other way around: Make a list of codes you want to keep and removing everything else! 如果你最终得到一长串需要删除的标签,也许你需要反过来:制作一个你想要保留的代码列表并删除其他所有代码!

  3. TRichEdit control: As far as I know there's no third party rich text editor, so you might as well treat problem (3) the same as problem (1). TRichEdit控件:据我所知,没有第三方富文本编辑器,所以你不妨把问题(3)和问题(1)一样对待。 Saying "This RTF is valid because it works fine in Microsoft Word 2010" doesn't help a single bit, unless you're willing to show your RTF in a Word window using OLE Automation! 说“这个RTF有效,因为它在Microsoft Word 2010中正常工作”并没有帮助,除非你愿意使用OLE自动化在Word窗口中显示你的RTF!

Other suggestions: 其他建议:

  • Show some code on how you actually build the big RTF. 显示一些关于如何实际构建大型RTF的代码。
  • If you do find an bad rtf tag and need more info, copy-paste the exact code: /f0protect is not valid rtf! 如果你找到一个坏的rtf标签并需要更多信息,请复制粘贴确切的代码: /f0protect无效rtf!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM