Delphi: How to exclude units from the debugger?


Sometimes as I am debugging step-by-step, just before a FormCreate Event or just after the FromDestroy the debugger starts to open DevExpress units (cxContainer.pas, ...) and so before FormCreate my "F8" leads me to cxContainer instead of going into the next line of my code.

(this is just an example, it can happen of course with any 3rd party library)

How do I tell the debugger "debug only my units" (only the pas files listed in dpr file?)

Of course sometimes it is useful to debug libraries, but in most cases it isn't.

You'd better follow VCL convention for your third-party components:

  • Change DCU output path in all the third-party packages to a folder different than the folder you store the PAS files.
  • Compile each package once in Debug mode, and save the generated DCU files in a folder (e.g. Debug DCUs).
  • Compile each package once again, but this time in Release mode, and save the generated DCU files in a folder (e.g. Release DCUs).
  • Go to Delphi options and add path of release DCUs to "Library path".
  • In Delphi options, add path of source files to "Browsing path".
  • In Delphi options, add path of debug DCUs to "Debug DCU path".

This way, Delphi will only see release DCUs of that third-party component when you are compiling your project, so the debugger cannot step into the source code. On the other hand, since source path is included in "Browsing path", you can still navigate to the source code inside IDE by Ctrl+Click on unit name, or anything defined in those units.

If you want to debug component, you can go to "Project | Options | Delphi Compiler | Compiling", and enable "Use debug .dcus". This will force compiler to use "Debug DCU path" instead of "Library path".

VCL works the same, generally you don't step into VCL source code when you are debugging your project, but if you enable "Use debug .dcus" you can debug VCL source code too.

JVCL also organizes its packages and source code the same way.

EDIT: If you take this approach, and want to have code browsing (Ctrl+Click) working; please take note that when you compile release version of packages, you must set Symbol Reference Info in "Project | Options | Delphi Compiler | Compiling" to "Reference Info"; otherwise, Ctrl+Click won't work for those units. By default, Release build configuration sets Symbol Reference Info to None.