使用换行符将文件从 AS 加载到 cl_gui_textedit
我想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果直接将 XML 文档呈现为
STRING
,然后将其发送到CL_GUI_TEXTEDIT
控件,会更容易:如果您必须渲染为二进制数据,那么我建议您使用
XSTRING
:然后您可以使用 SAP 提供的
CL_ABAP_CONV_IN_CE
类将二进制数据转换为字符串:您可以将其发送到
CL_GUI_TEXTEDIT
控件:请注意,如果遇到编码问题,您可以在渲染之前在 ostream 对象上设置编码,并且转换器对象允许您在创建它时指定编码。
It's easier if you render your XML document into a
STRING
straight away, which you can then send to yourCL_GUI_TEXTEDIT
control:If you must render into binary data, then I suggest you use an
XSTRING
for that:You can then convert the binary data to a string, using the
CL_ABAP_CONV_IN_CE
class provided by SAP:Which you can send to your
CL_GUI_TEXTEDIT
control: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.