使用换行符将文件从 AS 加载到 cl_gui_textedit

发布于 2024-12-25 19:56:16 字数 1015 浏览 1 评论 0原文

我想在 cl_gui_textedit 组件内显示一个带有换行符的文件,这给我带来了问题。

我使用以下代码来初始化组件

  DATA: lo_c_errorviewer TYPE REF TO cl_gui_custom_container.

  CREATE OBJECT lo_c_errorviewer
    EXPORTING
        container_name = 'C_ERROR_MSG'.

  CREATE OBJECT go_error_textedit
    EXPORTING parent = lo_c_errorviewer.

  go_error_textedit->set_toolbar_mode( 0 ).
  go_error_textedit->set_statusbar_mode( 0 ).

在使用 iXML 包进行一些 XML 处理之后,文件的二进制数据如下所示:

types: begin of xml_line,
        data(256) type x,
       end of xml_line.

data:  xml_table type table of xml_line,
       xml_size  type i.

ostream = streamFactory->create_ostream_itable( xml_table ).
document->render( ostream = ostream  recursive = 'X' ).
xml_size = ostream->get_num_written_raw( ).

如果我是对的,这应该包含换行符。 ostream 对象默认打开“漂亮打印”。

我搜索了参考文献,传递信息的唯一方法是通过

call method <c_textedit_control> - > set_text_as_stream

它需要一个字符的“标准表”。如何转换数据或将其传递给组件?

I want to display a file inside a cl_gui_textedit component with line breaks which causes me problems.

I am using the following code to initialize the component

  DATA: lo_c_errorviewer TYPE REF TO cl_gui_custom_container.

  CREATE OBJECT lo_c_errorviewer
    EXPORTING
        container_name = 'C_ERROR_MSG'.

  CREATE OBJECT go_error_textedit
    EXPORTING parent = lo_c_errorviewer.

  go_error_textedit->set_toolbar_mode( 0 ).
  go_error_textedit->set_statusbar_mode( 0 ).

After some XML processing with the iXML package the binary data of the file is available like this:

types: begin of xml_line,
        data(256) type x,
       end of xml_line.

data:  xml_table type table of xml_line,
       xml_size  type i.

ostream = streamFactory->create_ostream_itable( xml_table ).
document->render( ostream = ostream  recursive = 'X' ).
xml_size = ostream->get_num_written_raw( ).

This should contain line breaks if I am right. The ostream object has "pretty printing" turned on by default.

I searched the reference and the only way to pass the information is via

call method <c_textedit_control> - > set_text_as_stream

which expects a "Standard Table" of characters. How do I convert the data or pass it to the component?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么敢 2025-01-01 19:56:16

如果直接将 XML 文档呈现为 STRING,然后将其发送到 CL_GUI_TEXTEDIT 控件,会更容易:

data xmlstring type string.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_cstring( xmlstring ).
document->render( ostream = ostream recursive = 'X' ).
...
data textedit type ref to cl_gui_textedit.
create object textedit
  exporting
    parent = container.
textedit->set_textstream( xmlstring ).

如果您必须渲染为二进制数据,那么我建议您使用 XSTRING

data xmlxstring type xstring.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_xstring( xmlxstring ).
document->render( ostream = ostream recursive = 'X' ).

然后您可以使用 SAP 提供的 CL_ABAP_CONV_IN_CE 类将二进制数据转换为字符串:

data converter type ref to cl_abap_conv_in_ce.
converter = cl_abap_conv_in_ce=>create( input = xmlxstring ).
data xmlstring type string.
converter->read( importing data = xmlstring ).

您可以将其发送到 CL_GUI_TEXTEDIT 控件:

data textedit type ref to cl_gui_textedit.
create object textedit
  exporting
    parent = container.
textedit->set_textstream( xmlstring ).

请注意,如果遇到编码问题,您可以在渲染之前在 ostream 对象上设置编码,并且转换器对象允许您在创建它时指定编码。

It's easier if you render your XML document into a STRING straight away, which you can then send to your CL_GUI_TEXTEDIT control:

data xmlstring type string.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_cstring( xmlstring ).
document->render( ostream = ostream recursive = 'X' ).
...
data textedit type ref to cl_gui_textedit.
create object textedit
  exporting
    parent = container.
textedit->set_textstream( xmlstring ).

If you must render into binary data, then I suggest you use an XSTRING for that:

data xmlxstring type xstring.
data ostream type ref to if_ixml_ostream.
ostream = streamfactory->create_ostream_xstring( xmlxstring ).
document->render( ostream = ostream recursive = 'X' ).

You can then convert the binary data to a string, using the CL_ABAP_CONV_IN_CE class provided by SAP:

data converter type ref to cl_abap_conv_in_ce.
converter = cl_abap_conv_in_ce=>create( input = xmlxstring ).
data xmlstring type string.
converter->read( importing data = xmlstring ).

Which you can send to your CL_GUI_TEXTEDIT control:

data textedit type ref to cl_gui_textedit.
create object textedit
  exporting
    parent = container.
textedit->set_textstream( xmlstring ).

Note that in case you run into encoding issues, you can set the encoding on the ostream object before rendering, and the converter object allows you to specify encoding when you create it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文