有没有办法在Delphi中只跟踪项目源? [英] Is there a way to trace through only project source in Delphi?

查看:111
本文介绍了有没有办法在Delphi中只跟踪项目源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi 2010,我想知道是否有办法跟踪项目中的代码,而无需通过调用包含的VCL进行跟踪。



例如 - 您放入一个断点,然后使用 Shift + F7 逐行追踪。现在,您可以在VCL中调用一些冗长的过程 - 在我的情况下,它通常是一个Measurement Studio或其他组件,用于绘制一堆I / O,OPC或其他位。无论如何,发生的是调试器跳出活动源文件,打开组件源,并逐行追踪。通常这是数百或数千行代码,我不在乎 - 我只想让它执行并返回到MY项目中的下一个源代码行。



显然,您可以通过在外部呼叫的每个实例上设置断点来实现此目的,但通常有太多可以实现这一点 - 我会花一个小时的时间每次我想通过一段代码时,都会有一百个断点。



有没有一个设置或工具可以做到这一点?允许一个人在项目中跟踪代码,而默认执行项目外部的代码?

解决方案

调试器不会逐步通过不具有调试信息的单元,所以目标是使编译器从您不感兴趣的单元中省略调试信息。



将您的库单位在一个单独的图书馆项目。这使您能够为这些单元分开编译设置,而不影响您的项目。编译库,而不启用调试信息。然后从项目中删除这些库单元。您可以继续使用它们,但它们不再属于您的项目。



这里的一个重要方面是, DCU应驻留在单独的目录中源代码。如果编译器发现DCU,并且恰好在同一个文件夹中看到源代码,那么当您不想要的时候,它可能会重新编译该代码。将项目的DCU输出文件夹设置为默认值。



为了真正做到正确,您可以执行VCL的工作,并编译两个不同版本的你的图书馆编译一个调试信息,一个没有,并将编译的文件放在不同的目录中。将具有调试版本的目录添加到Delphi配置中;应该已经有一个包含Delphi提供的调试DCU的文件夹。



当您设置两个不同的版本时,您允许自己选择是否要步骤进入图书馆代码。只需在项目设置中切换使用调试DCU选项即可。当您切换该设置时,Delphi会自动从搜索路径添加和删除调试版本文件夹。






请注意,即使虽然您将有一个单独的库项目为您的库单位,您不需要链接或分发该项目生成的DLL或包。您可以直接在EXE项目中直接使用DCU文件。您只设置单独的项目,以便您可以为这些单元选择不同的编译设置。将库项目的DCU输出文件夹添加到EXE项目的搜索路径,您可以直接继续使用这些单元,而无需分发库项目的DLL或程序包。



IDE可能会尝试自动将新的目录添加到搜索路径。不要这样如果有一个源目录,IDE为您添加,您不希望它在那里,请随意删除它。 IDE只是试图有所帮助,但它不知道你有计划单独的源和编译文件夹。


I'm using Delphi 2010 and I'm wondering if there's a way to trace through code which is in the project without tracing through calls to included VCLs.

For example - you put in a breakpoint and then use Shift+F7 to trace through line-by-line. Now you run into a call to some lengthy procedure in a VCL - in my case it's often a Measurement Studio or other component that draws the doodads for a bunch of I/O, OPC, or other bits. At any rate, what happens is that the debugger hops out of the active source file, opens the component source, and traces through that line by line. Often this is hundreds or thousands of lines of code I don't care about - I just want to have it execute and return to the next source line in MY project.

Obviously you can do this by setting breakpoints around every instance of an external call, but often there are too many to make this practical - I'd be spending an hour setting a hundred breakpoints every time I wanted to step through a section of code.

Is there a setting or a tool somewhere that can do this? Allow one to trace through code within the project while silently executing code which is external to the project?

解决方案

The debugger won't step through units that don't have debug information, so the goal is to make the compiler omit debug information from the units you're not interested in.

Put your library units in a separate library project. That gives you the ability to have separate compilation settings for those units without affecting your project. Compile the library without debugging information enabled. Then remove those library units from your project. You can continue using them, but they won't belong to your project anymore.

An important aspect here is that the DCUs should reside in a separate directory from the source code. If the compiler finds DCUs and it happens to see the source code in the same folder, then it's liable to recompile that code when you really don't want it to. Set your projects' "DCU output folder" to something other than the default.

To really do it right, you can do what the VCL does and compile two different versions of your libraries. Compile one with debug information, and one without, and put the compiled files in different directories. Add the directory with the debug versions to your Delphi configuration; there should already be a folder listed there that contains the Delphi-provided debug DCUs.

When you set up two different versions, you allow yourself to choose whether you want to step into the library code. Simply toggle the "use debug DCUs" option in your project settings. Delphi will automatically add and remove the debug-version folder from the search path when you toggle that setting.


Note that even though you'll have a separate library project for your library units, you don't need to link to or distribute the DLL or package that that project generates. You can continue using the DCU files directly in your EXE project. You're only setting up the separate project so that you can select different compilation settings for those units. Add the library project's DCU output folder to your EXE project's search path, and you can continue using the units directly without any need to distribute the library project's DLL or package.

The IDE may try to add new directories to the search path automatically. Don't stand for that. If there's a source directory there that the IDE added for you and you don't want it there, feel free to remove it. The IDE is just trying to be helpful, but it doesn't know about your plan to have separate source and compiled folders.

这篇关于有没有办法在Delphi中只跟踪项目源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆