简体   繁体   English

如何在Delphi应用程序中找到所有单元?

[英]How can I find all the units in my Delphi app?

It's easy enough to find all your external dependencies. 找到所有外部依赖项很容易。 Just run the program and open up the Modules info window. 只需运行程序并打开模块信息窗口即可。 But how can I find all my internal dependencies? 但是我怎样才能找到所有内部依赖项? I know the program keeps a list of all the units, because I've traced my way through the initialization code a time or two. 我知道程序会保留所有单元的列表,因为我已经在初始化代码中跟踪了一两次。 But is there any easy way to access this list from the debugger? 但有没有简单的方法从调试器访问此列表?

The Delphi debugger can show you which units were compiled into a module (exe, dll or package). Delphi调试器可以显示哪些单元被编译成模块(exe,dll或包)。 You can see this in the Modules view (View | Debug Windows | Modules). 您可以在Modules视图中查看(View | Debug Windows | Modules)。 Click on a module in the upper left pane, and the lower left pane will show all the compilation units that were built into that module. 单击左上窗格中的模块,左下窗格将显示该模块中内置的所有编译单元。 If a particular compilation unit was made up of multiple source files (ie a .pas and a .inc file), that will be shown too (when you expand the comp unit). 如果特定的编译单元由多个源文件(即.pas和.inc文件)组成,那么也会显示(当您展开comp单元时)。

Alternatively, you can have the Delphi compiler show you a list of used .dcus by passing --depends when you compile a project. 或者,您可以让Delphi编译器在编译项目时通过传递--depends向您显示已使用的.dcus列表。 It will output a .d file with a list of the .dcus (and .dcps) that were required. 它将输出一个.d文件,其中包含所需的.dcus(和.dcps)列表。

I use the GExperts Project Dependencies. 我使用GExperts项目依赖项。
With the "Used By...", you can see units included but not used by anyone. 使用“Used By ...”,您可以看到包含但未被任何人使用的单位。 But you can't see unit included in uses clauses that could be removed when they don't have any code actually called. 但是你看不到包含在use子句中的单元,当它们没有任何实际调用的代码时可以删除。

Here's the help: 这是帮助:


Project Dependencies 项目依赖性

The project dependency expert enables you to see what units a particular unit uses, and in turn what units use a particular unit. 项目依赖性专家使您能够查看特定单位使用的单位,以及使用特定单位的单位。 When this expert is activated, it parses all of the current project's source code for uses clauses and builds up a list of dependencies. 激活此专家后,它会解析当前项目的所有使用子句的源代码,并构建依赖项列表。 To view the dependency information for a particular unit, click on it in the left pane. 要查看特定单元的依赖关系信息,请在左窗格中单击它。 The right pane will contain the dependency information. 右侧窗格将包含依赖项信息。 Indirect dependencies are units that are used by used units of a particular unit. 间接依赖性是特定单位的使用单位使用的单位。

You can refresh the dependency information at any time by clicking the refresh button on the toolbar and you can sort the file listing by clicking on the column headers. 您可以通过单击工具栏上的刷新按钮随时刷新依赖关系信息,也可以通过单击列标题对文件列表进行排序。
替代文字
(source: gexperts.org ) (来源: gexperts.org


OTOH, you can also use free Peganza's ICARUS as a more detailed reporting tool but less interactive... OTOH,您也可以免费使用Peganza的ICARUS作为更详细的报告工具,但交互性较差......

Another, but rather cumbersome way, is to generate a map file, it contains a list of all units used in a program. 另一种相当麻烦的方法是生成一个映射文件,它包含程序中使用的所有单元的列表。

see also this answer: How can I find all the units in my Delphi app? 另见这个答案: 我怎样才能找到我的Delphi应用程序中的所有单元?

Have you looked at Pascal Analyzer or the free limited version, Icarus, from Peganza Software ? 您是否看过Pasgan Analyzer或Peganza Software的免费限量版Icarus? They will create "uses reports" telling you what module uses what others, so that should give you the info you're after. 他们将创建“使用报告”,告诉您哪个模块使用了其他模块,因此应该为您提供您所追求的信息。

Marc

GExperts has a Project Dependencies tool. GExperts有一个Project Dependencies工具。 I have used it before when trying to track down used units. 我在尝试追踪用过的单位之前使用过它。 You can't search in it but you can export the list to a CSV file and search there. 您无法在其中进行搜索,但可以将列表导出为CSV文件并在那里搜索。 This also only lists what is in the uses section. 这也仅列出了使用部分中的内容。 If you have a module included that is not being used it will still show up. 如果您有一个未使用的模块,它仍会显示。

I know of at least two ways you could try to get a view of all the units used in your project 我知道至少有两种方法可以尝试查看项目中使用的所有单位

  1. CTRL-SHIFT-B opens the object browser. CTRL-SHIFT-B打开对象浏览器。 If I'm not mistaken, here you can get a view of used units. 如果我没有弄错的话,在这里你可以看到用过的单位。 I'm not entirely sure about this method and don't have Delphi available to verify it. 我不完全确定这种方法,也没有Delphi可用来验证它。
  2. Use Modelmaker ; 使用Modelmaker ; Modelmaker can give you a tree like view of all your unit dependancies. 模型制作者可以为您提供所有单位依赖性视图的树。 Look at the Visualizing existing code section for more information. 查看可视化现有代码部分以获取更多信息。

The easiest way is to compile program and check which .dcu was created by compiler. 最简单的方法是编译程序并检查编译器创建的.dcu Make sure to setup compiler to create .dcu in a separate directory, for example c:\\dcu . 确保设置编译器以在单独的目录中创建.dcu ,例如c:\\dcu I have created simple utility that searches .pas for every .dcu file in directories that are in a compiler search path (that can be read from .cfg , .dof or .bdsproject file). 我创建了简单的工具,搜索.pas为每.dcu在有能力的编译器搜索路径的目录文件(即可以读取.cfg.dof.bdsproject文件)。

You can use a MAP file in conjunction with MapFileStats , this will not just give you all your dependencies, but the amount of code (and resources) they contribute in the final executable. 您可以将MAP文件与MapFileStats结合使用,这不仅会为您提供所有依赖项,还会为您提供最终可执行文件中的代码(和资源)数量。

Useful to spot units you have dependencies to, but use little of, as well as spotting "fat hog" units, which take everything plus the kitchen sink with them. 有用的发现你有依赖的单位,但使用很少,以及发现“肥猪”单位,这些单位带有所有东西加上厨房水槽。

FWIW, reducing dependencies and eliminating hogs isn't just beneficial to executable size, it's also beneficial down the road when it'll be time to upgrade to a new version. FWIW,减少依赖性和消除生猪不仅有利于可执行的大小,当它升级到新版本时,它也是有益的。

There is a (rather old) utility called UsgParse. 有一个(相当古老的)实用工具叫做UsgParse。 It builds a treeview of all units referenced by a project. 它构建了项目引用的所有单元的树视图。

I found a copy on the NexusDB site via http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.thirdpartytools.general/2004-03/0231.html 我通过http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.thirdpartytools.general/2004-03/0231.html在NexusDB网站上找到了一份副本。

source: http://www.nexusdb.com/downloads/USGParse/USGParse_src.zip 来源: http//www.nexusdb.com/downloads/USGParse/USGParse_src.zip

binary: http://www.nexusdb.com/downloads/USGParse/USGParse.zip 二进制文件: http//www.nexusdb.com/downloads/USGParse/USGParse.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM