绕过 Delphi 中的循环引用 [英] getting around circular references in Delphi
问题描述
有没有办法绕过 Delphi 中的循环单元引用?
Is there a way of getting around circular unit references in Delphi?
也许是更新版本的 delphi 或一些魔法黑客之类的?
Maybe a newer version of delphi or some magic hack or something?
我的 delphi 项目有 100 000 多行代码,主要基于单例类.我需要重构这个,但这意味着几个月的循环引用"地狱:)
My delphi project has 100 000+ lines of code mostly based on singleton classes. I need to refactor this, but that would mean several months of "circular reference" hell :)
推荐答案
在过去的 10 年中,我一直在维护近一百万行遗留代码,所以我理解您的痛苦!
I've been maintaining close to a million lines of legacy code for the past 10 years so I understand your pain!
在我维护的代码中,当我遇到循环使用时,我经常发现它们是由单元B需要的单元A中的常量或类型定义引起的.(有时也是一小段代码单元 B 也需要单元 A 中的(甚至全局变量).
In the code that I maintain, when I've encountered circular uses, I frequently have found that they are caused by constants or type definitions in unit A that are needed by unit B. (Sometimes it's also a small bit of code (or even, global variables) in Unit A that is also needed by unit B.
在这种情况下(如果我很幸运!)我可以小心地将代码的这些部分提取到一个包含常量、类型定义和共享代码的新单元 C 中.那么A单元和B单元使用C单元.
In this situation (when I'm lucky!) I can carefully extract those parts of the code into a new unit C that contains the constants, type definitions, and shared code. Then units A and B use unit C.
我在发表上述内容时有些犹豫,因为我不是软件设计方面的专家,并且意识到这里有很多其他人比我知识渊博.不过,希望我的经验对您有所帮助.
I post the above with some hesitance because I'm not an expert on software design and realize there are many others here who are far more knowledgeable than I am. Hopefully, though, my experience will be of some use to you.
这篇关于绕过 Delphi 中的循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!