如何识别并删除“使用条款”中未使用的单位? 在德尔福7中?
在我的一些非常大的项目中,这应该会大大减少可执行文件的大小。 我确信还会有其他好处。
编辑:是否有一个实用程序可以扫描项目并自动删除多余的项目? 我确实有数百个项目,“自动删除”将是一等奖,尽管如果必须的话,我会在识别实用程序的帮助下采用手动方式。
This should reduce the executable size quite a bit in some of my very large projects. I am sure there would be other benefits too.
EDIT: Is there perhaps a utility that will scan the project and remove redundant ones automatically? I do have 100s of projects and "automatic remove" would be first prize although if I have to I will go the manual way with the help of identifying utilities.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可能想看看 CnPack。
CnPack 包含一个使用清理向导,它还没有让我失望。
You might want to take a look at at CnPack.
CnPack includes a Uses cleaner wizard wich hasn't failed me yet.
我曾经使用 Icarus 它给了我一份未使用的使用条目的报告。
从网页上
I used to use Icarus that gave me a report of unused uses entries.
From the web page
这样的工具永远无法分析所使用单元的初始化或终结部分是否需要执行。 从使用中删除单元可能会导致不运行初始化和终结部分,从而导致错误。
Such a tool can never analyze if the initialization or finalization sections of a used unit need to be executed or not. Removing units from the uses could result in not running initialization and finalization sections and therefore result in bugs.
如果您的代码可以使用 Free Pascal 进行编译,则 Free Pascal 编译器还会发出有关代码中未使用单元的提示。
另请参阅此 SO 条目,其中包含有关可能问题的其他信息,例如基于 RTTI 的方法:
https://stackoverflow.com/questions/605977/tools-to-detect-dead-code-in-delphi2007-or-above/
If your code can be compiled with Free Pascal, the Free Pascal compiler also will emit hints about unused units in your code.
See also this SO entry with additional information about possible problems, like RTTI based methods:
https://stackoverflow.com/questions/605977/tools-to-detect-dead-code-in-delphi2007-or-above/
请记住,链接器将删除任何无法调用的内容。 如果一个单元没有被使用并且没有初始化或终结,那么它无论如何都会被完全剥离。 初始化或终结中引用的任何内容都将保留,但一般来说这不会带来太多影响。
一个单元可能只包含初始化,因此全自动剥离无论如何都会受到限制。 仅以某种方式改变系统行为的单元很可能没有引用,但仍然需要。 (我想到了具有良好泄漏跟踪功能的替换内存管理器。虽然它确实有您可以参考的东西,但没有必要,只需使用它并获取泄漏报告即可。仔细检查您的代码。)
Remember that the linker will strip anything that can't be called. If no use is made of a unit and it has no initialization or finalization it's going to be completely stripped anyway. Anything referenced in the initialization or finalization will stay but in general this shouldn't bring in much anyway.
It's possible for a unit to consist of only initialization so full-auto stripping is limited anyway. Units which merely change system behavior in some fashion might very well have no references and yet be needed. (The replacement memory manager with good leak tracking comes to mind. While it does have things you can reference there's no need to, just use it and get the leak report. Nice double-check for your code.)
请参阅此处的一些答案。
See some of the answers here.
Peganza 有类似的工具:http://www.peganza.com/
Peganza has similar tools: http://www.peganza.com/