I am trying to run a debug on my code, but somehow it stopped working. Here is a snippet and the green lines it is showing:
- I have tried to right click on my project and
clean
it. - Tried
to delete temporary files, like
.stat
and.dcu
. - Switching back and forth to
Release
andDebug
modes, rebuilding, recompiling them. - The
Debugging
options underProject -> Options -> Delphi compiling
are all set to true. - Checked if there are no duplicate files in the
search paths
. - Other projects are working correctly.
- Also tried swearing.
What am I doing wrong?
It is a kind of normal compiler behaviour. It ever happens when the procedure (code line) is never called from anywhere inside your program. Compiler skips such procedures and functions (all the code lines within them). See the picture.
You just need to check if the procedure (line) is really at least once called from anywhere inside your application.
Appended
This also takes place when the code line can never be called and this (the logic statement) can be evaluated at compilation (the result is known in advance and can not be affected at runtime). The compiler optimizes the code skipping such lines. That is why it does not accept breaks at them.
Here is a diassembly of the latter procedure. The
if false then ...
statement at lines 37 and 38 is omitted:Adding to the answer from asd-tm, I include the following line in all my units:
In the ProjOptions.inc file, I include the following code:
In this way, optimisation is off and debug information switched on when I am debugging without me worrying about accidentally toggling something in Project > Options. Manually deleting DCU files from the PROJECT\objects folder (combined with the above .inc file) should guarantee breakpoints working again (at least in DEBUG builds).