在单元破坏调试信息中通用定义

发布于 2024-09-27 05:07:07 字数 670 浏览 1 评论 0原文

这一定是 Delphi 的 bug...

我有一个单元,它是我的持久性框架的基础。在该单元中,我有一个用于所有域对象的基类、一个列表类和一个通用列表类。

就在最近,我注意到当我在调试时进入单元时,执行会跳转到文件中比应有的位置更靠下的位置......也许四到五行。重新排序文件没有什么区别。该代码还会生成访问冲突,但仅在我对其进行调试时才会发生。

我试图找出这个问题的原因...我想到了几件事,比如调试器中的一些代码注入(例如 这个 logitec 网络摄像头驱动程序错误),或者调试信息与我的设备源不同步(例如,dcu 是从某些旧源中提取的)。

最后,我启动了一个安装了干净的 Windows + Delphi 的虚拟机,仅获取测试该单元所需的内容,并创建了一个小型 DUnit 项目来测试它。同样的问题。

然后我开始一次一个地从设备中移除一些东西,直到它起作用为止。唯一有区别的是当我删除通用列表类时。

还有其他人看到这个问题吗?有谁知道如何解决它?

预先感谢,

N@

更新:将通用添加回设备会使问题再次出现,因此这不是陈旧的 DCU 的问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云胡 2024-10-04 05:07:07

您是否确保相关单元的所有行都以 CR LF 结尾?调试器不能只处理 CR 或 LF,而编辑器可以。 Notepad++、TextPad 等可以显示是否存在混合物。在[Windows]记事本中加载并重新保存即可解决。

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.

等待我真够勒 2024-10-04 05:07:07

最后,我发现唯一有效的解决方案是将通用列表移出该单元。

更新 2011-08-03 为了更好地充实我的解决方案:

我在我的 Domain 单元中使用我的基 TDomainObject 定义了通用列表基类类和非通用版本。

为了解决这个问题,我将泛型移到了第二个 Domain.Generics 单元中,这为我解决了问题。

所以:

unit Domain;

interface 

type
  TDomainObject = class
    //blah de blah
  end;

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

  TDomainListEnumerator = class
    //etc
  end;

并且:

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;

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;
耀眼的星火 2024-10-04 05:07:07

通常这是内部/外部编译状态不同步。

第一步是删除项目的 .dcu 文件,然后重新启动 Delphi,然后进行完整构建。如果问题仍然存在,请查看Nick 的回答

——杰罗恩

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文