【问题标题】:Delphi XE7,Unicode display problems with PageProducer on WebBrokerDelphi XE7,WebBroker 上 PageProducer 的 Unicode 显示问题
【发布时间】:2015-01-28 12:06:58
【问题描述】:

我正在编写一个多语言 WebBroker 应用程序(用于 Apache 2.2),它显示来自 oracle 数据库的 unicode 编码数据。在用 Delphi XE7 编写的测试程序中,具有相同数据感知组件(Devart 的 ODAC)的相同数据可以正确显示。 我的问题出现在 WebBroker 中,当我使用 PageProducer 为响应准备内容时,我遇到了奇怪的行为 当我在操作中使用以下代码时:

Response.ContentType := 'text/html; charset=UTF-8';
PageProducer1.HTMLFile:= htmltemplate
Response.Content := 
  PageProducer1.Content+
  'Label 1 ='+Label1fromDB+
  ' Label 2='+Label2fromDB+
  '</body></html>';
Response.SendResponse;

webbrowser 中的结果是所有未由 PageProducer 插入但已存在于 htmltemplate 文件中的非拉丁字符(已声明为 utf-8 with )被其他不正确的字符替换,文本由 PageProducer 插入并从数据库中检索也未正确显示,但添加到内容响应中的额外标签 Label1fromDB 和 Label2fromDB 正确显示,如上面的代码所示,它们也具有与 htmltemplate 中相同的字符。

现在,当我省略声明时

Response.ContentType := 'text/html; charset=UTF-8'

html模板的内容显示正确,但所有其他文本,由PageProducer填充的文本以及Label1fromDB和Label2fromDB两个标签不正确

您能否帮我确定问题出在哪里以及我做了什么才能通过网络代理提供 unicode 多语言内容?

【问题讨论】:

    标签: delphi unicode delphi-xe7


    【解决方案1】:

    您在使用不同的 Unicode 编码时遇到问题。

    PageProducer.ContentResponse.Content 都是 UTF16 编码字符串。您的htmltemplate 编码为UTF8,而PageProducer 未正确解释。

    最可能的原因是htmltemplate 文件开头没有UTF8 BOMPageProducer 会将文件编码解释为默认ANSI。如果是这样,添加UTF8 BOM 应该可以解决您的问题。

    【讨论】:

    • 非常感谢您的澄清 Dalija,问题解决了,正是这个在 html 开头省略了 BOM。所以我生成了一个新的 html 文件,其中 BOM 和 PageProducer 编码正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 2015-06-17
    • 1970-01-01
    • 2022-08-15
    • 2015-02-25
    • 2014-11-05
    相关资源
    最近更新 更多