5
votes

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.

3
Natalie, I have the same problem which is really annoying because I have a whole project based on generic lists. When I started the debug - surprise! - the Delphi IDE crashed. I started a bounty for your question. If you have founded any workaround for this Delphi bug, please write down here. - Andrew
@Andrew I ended up creating a second unit with only the generics in it. I'll update my answer to better explain it... - Nat
Thanks for the exaplanation very much! It worked for me too. These +200 pts are yours, you have cured my headache :) - Andrew

3 Answers

2
votes

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.

2
votes

In the end, the only solution that I could find that worked was to move the generic list out of the Unit.

Update 2011-08-03 To better flesh out my solution:

I had my generic list base class defined in my Domain unit with my base TDomainObject class and a non-generic version.

To fix the problem, I moved the generic into a second Domain.Generics unit which resolved the problem for me.

So:

unit Domain;

interface 

type
  TDomainObject = class
    //blah de blah
  end;

  TDomainObjectList = class (TDomainObject)
    //more stuff
  end;

  TDomainListEnumerator = class
    //etc
  end;

And:

unit Domain.Generics;

interface

type

  TDomainObjectList<T: TDomainObject> = class (TDomainObjectList)
    //stuff
  public
    property Items[AIndex: integer]: T read GetItem write SetItem;

    type
      TEnumerator = class (TDomainListEnumerator)
      public
        function GetCurrent: T;
        property Current: T read GetCurrent;
      end;

  public
    function GetEnumerator: TEnumerator;

  end;
0
votes

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