views:

61

answers:

2

This must be a Delphi bug...

I have a unit which is the basis of my persistance framework. In that unit I have a base class for all my domain objects, a list class and a generic list class.

Just recently I noticed that when I step into the unit when debugging, execution will jump to a point a little further down in the file than it should... Maybe four or five lines. Re-ordering the file makes no difference. The code would also generate access violations, but only when I debugged it.

I cast about trying to find the reason for this... Several things came to mind, like some code injection screwing with the debugger (eg this logitec webcam driver bug), or the debug info being out of sync with my unit source (eg the dcu was being pulled from some old source).

In the end I fired up a VM with a clean Windows + Delphi install, grabbed only what I needed to test the unit, and I created a small DUnit project to test it. Same problem.

Then I started removing things from the unit one at a time till it worked. The only thing that made any difference was when I removed the generic list class.

Has anyone else seen this problem? Does anyone know how to get around it?

Thanks in advance,

N@

Update: Adding the generic back into the unit makes the problem come back, so it's not a problem of stale DCUs.

+2  A: 

Have you ensured that all lines of the unit in question end in CR LF? The debugger can't handle just CR or LF while the editor can. Something like Notepad++, TextPad, etc can show you if there is a mixture. Loading it up in [Windows] NotePad and re-saving it can resolve it.

Nick RIng
If that is the case, how could removing the generic from the unit have fixed the problem?
Nat
I have now done as you have suggested, and no change. If the generic is in the file, the debug info is broken, if it's out, debug info is fine. Thanks for your suggestion, BTW.
Nat
A: 

Often this is the internal/external compile state getting out of sync.

First step is to get rid of the .dcu files for your project, then restart Delphi, then do a full build. If the problem persists, then check out Nick's answer.

--jeroen

Jeroen Pluimers
I did that, that's why I checked out the code on a clean machine with a clean Delphi installed... No DCU's were on the machine at all. After removing bits from the unit, and several compile cycles it was only _after_ removing the generic that fixed the problem... Indeed, putting it back into the unit made the problem re-occur.
Nat
If it is a simple unit, put it in the question. I'll try to reproduce it with both Delphi 2010 and Delphi XE.
Jeroen Pluimers
I'll pair it down to a small example and then post it... But it will have to wait till Monday (Melbourne time) now. Thanks for your advice so far.
Nat