如何在调试器中显示 TStringList 的内容?
我想在调试应用程序时显示 TStringList 的全部内容。 相反,我只是得到指示。 Flist 仅显示地址。
I want to display the entire content of a TStringList while debugging the application.
Instead I just get pointers. The Flist is showing only the address.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用的是 Delphi 2010 或更高版本,调试器允许使用调试可视化工具来实现此目的。
对于旧版本,您可以在“监视”窗口中转储 Text 属性的内容或使用 OutputDebugString,但这很难阅读。您可以为列表中的每个元素设置监视,但这仅适用于非常短的列表。
我可能会使用外部日志记录应用程序,例如 CodeSite 或 SmartInspect 可让您在一次调用中转储 TStringList 的内容。
If you are using Delphi 2010 or later, the debugger allows for this using debug visualizers.
For older versions, you can dump the contents of the Text property in the Watch window or using OutputDebugString, but that's difficult to read. You could set up watches for each element of the list, but that's only practical for very short lists.
I would probably use an external logging app like CodeSite or SmartInspect that let you dump the contents of a TStringList in a single call.
检查文本属性。它是字符串列表的串联版本。
Inspect the Text property. It's the concatenated version of the stringlist.
由于我使用的是 BDS MMVI,因此我使用“超聪明”方法来解决此类问题,我将其用于大型 xml 文档。我启动上下文文件编辑器(顺便说一句,用 delphi 编写的功能非常强大的免费文本编辑器)。在调试器窗口上只需执行 FList.SaveToFile('contents.txt'),因为上下文可以监视文件修改,所以我可以看到 xml 文件中发生的情况。
抱歉这个“聪明”的笑话,但它确实对我有用。
和平
Since i´m using BDS MMVI, i´m using an "ultra clever smart" method for that kind issue, i use it for large xml documents. I start context file editor (very capable free text editor writen in delphi by the way). On the debugger window a just do a FList.SaveToFile('contents.txt'), since context can monitor file modifications i can see whats happening in my xml files.
Sorry for the "clever" joke but it does work for me.
Peace
我现在有了 D2010,就开始使用可视化工具。我曾经使用一个名为 CArray 的函数,它会返回一个字符串数组。如果我将 CArray(MyStringList) 添加到监视窗口,我将能够检查字符串列表的内容。我曾经受雇编写 VB6 代码,我有点喜欢用于转换为有用类型的各种“C”函数。用于字符串列表的 CArray 和用于 ClientDataset 字段的 CArray 对于调试最有用。
I use the visualizers now that I have D2010. I used to use a function I called CArray that would return an array of strings. If I added CArray(MyStringList) to the watch window, I would be able to examine the contents of the string list. I used to be employed to write VB6 code and I sort of liked the various 'C' functions for converting to a useful type. CArray for stringlists and CArray for ClientDataset fields were mostly useful for debugging.
我的两分钱:
您可以评估表达式
list_instance_variable.SaveToFile('temp_file_name.txt')
,然后在任何编辑器中检查文件的内容。为此,您必须在代码中的任何位置使用此函数并关闭优化(至少在 Delphi 7 中),否则
SaveToFile
的目标代码将被链接器删除。My two cents:
You can evaluate expression
list_instance_variable.SaveToFile('temp_file_name.txt')
and then examine content of the file in any editor.To do that you must use this function anywhere in code and turn off optimization (at least in Delphi 7), otherwise object code of
SaveToFile
would be removed by the linker.