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

时间:2022-02-24 19:34:24

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?

找到所有外部依赖项很容易。只需运行程序并打开模块信息窗口即可。但是我怎样才能找到所有内部依赖项?我知道程序会保留所有单元的列表,因为我已经在初始化代码中跟踪了一两次。但有没有简单的方法从调试器访问此列表?

9 个解决方案

#1


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应用程序中找到所有单元?

#2


The Delphi debugger can show you which units were compiled into a module (exe, dll or package). You can see this in the Modules view (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 (i.e a .pas and a .inc file), that will be shown too (when you expand the comp unit).

Delphi调试器可以显示哪些单元被编译成模块(exe,dll或包)。您可以在Modules视图中查看(View | Debug Windows | Modules)。单击左上窗格中的模块,左下窗格将显示该模块中内置的所有编译单元。如果特定的编译单元由多个源文件(即.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. It will output a .d file with a list of the .dcus (and .dcps) that were required.

或者,您可以让Delphi编译器在编译项目时通过传递--depends向您显示已使用的.dcus列表。它将输出一个.d文件,其中包含所需的.dcus(和.dcps)列表。

#3


I use the GExperts Project Dependencies.
With the "Used By...", you can see units included but not used by anyone. But you can't see unit included in uses clauses that could be removed when they don't have any code actually called.

我使用GExperts项目依赖项。使用“Used By ...”,您可以看到包含但未被任何人使用的单位。但是你看不到包含在uses子句中的单元,当它们没有任何实际调用的代码时可以删除。

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.
alt text http://www.gexperts.org/tour/project%20dependencies.png

您可以通过单击工具栏上的刷新按钮随时刷新依赖关系信息,也可以通过单击列标题对文件列表进行排序。 alt text http://www.gexperts.org/tour/project%20dependencies.png


OTOH, you can also use free Peganza's ICARUS as a more detailed reporting tool but less interactive...

OTOH,您也可以免费使用Peganza的ICARUS作为更详细的报告工具,但交互性较差......

#4


Have you looked at Pascal Analyzer or the free limited version, Icarus, from Peganza Software? They will create "uses reports" telling you what module uses what others, so that should give you the info you're after.

您是否看过Pasgan Analyzer或Peganza Software的免费限量版Icarus?他们将创建“使用报告”,告诉您哪些模块使用了其他模块,因此应该为您提供您所追求的信息。

Marc

#5


GExperts has a Project Dependencies tool. 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. 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.

GExperts有一个Project Dependencies工具。我在尝试追踪用过的单位之前使用过它。您无法在其中进行搜索,但可以将列表导出为CSV文件并在那里搜索。这也仅列出了使用部分中的内容。如果您有一个未使用的模块,它仍会显示。

#6


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. 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.
  2. CTRL-SHIFT-B打开对象浏览器。如果我没有记错的话,在这里你可以看到用过的单位。我不完全确定这种方法,也没有Delphi可用来验证它。

  3. Use Modelmaker; Modelmaker can give you a tree like view of all your unit dependancies. Look at the Visualizing existing code section for more information.
  4. 使用Modelmaker;模型制作者可以为您提供所有单位依赖性视图的树。查看可视化现有代码部分以获取更多信息。

#7


The easiest way is to compile program and check which .dcu was created by compiler. Make sure to setup compiler to create .dcu in a separate directory, for example 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).

最简单的方法是编译程序并检查编译器创建的.dcu。确保设置编译器以在单独的目录中创建.dcu,例如c:\ dcu。我创建了一个简单的实用程序,可以在编译器搜索路径(可以从.cfg,.dof或.bdsproject文件中读取)的目录中搜索每个.dcu文件的.pas。

#8


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,减少依赖性和消除生猪不仅有利于可执行的大小,当它升级到新版本的时候,它也是有益的。

#9


There is a (rather old) utility called UsgParse. It builds a treeview of all units referenced by a project.

有一个(相当古老的)实用工具叫做UsgParse。它构建了项目引用的所有单元的树视图。

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

binary: http://www.nexusdb.com/downloads/USGParse/USGParse.zip

#1


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应用程序中找到所有单元?

#2


The Delphi debugger can show you which units were compiled into a module (exe, dll or package). You can see this in the Modules view (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 (i.e a .pas and a .inc file), that will be shown too (when you expand the comp unit).

Delphi调试器可以显示哪些单元被编译成模块(exe,dll或包)。您可以在Modules视图中查看(View | Debug Windows | Modules)。单击左上窗格中的模块,左下窗格将显示该模块中内置的所有编译单元。如果特定的编译单元由多个源文件(即.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. It will output a .d file with a list of the .dcus (and .dcps) that were required.

或者,您可以让Delphi编译器在编译项目时通过传递--depends向您显示已使用的.dcus列表。它将输出一个.d文件,其中包含所需的.dcus(和.dcps)列表。

#3


I use the GExperts Project Dependencies.
With the "Used By...", you can see units included but not used by anyone. But you can't see unit included in uses clauses that could be removed when they don't have any code actually called.

我使用GExperts项目依赖项。使用“Used By ...”,您可以看到包含但未被任何人使用的单位。但是你看不到包含在uses子句中的单元,当它们没有任何实际调用的代码时可以删除。

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.
alt text http://www.gexperts.org/tour/project%20dependencies.png

您可以通过单击工具栏上的刷新按钮随时刷新依赖关系信息,也可以通过单击列标题对文件列表进行排序。 alt text http://www.gexperts.org/tour/project%20dependencies.png


OTOH, you can also use free Peganza's ICARUS as a more detailed reporting tool but less interactive...

OTOH,您也可以免费使用Peganza的ICARUS作为更详细的报告工具,但交互性较差......

#4


Have you looked at Pascal Analyzer or the free limited version, Icarus, from Peganza Software? They will create "uses reports" telling you what module uses what others, so that should give you the info you're after.

您是否看过Pasgan Analyzer或Peganza Software的免费限量版Icarus?他们将创建“使用报告”,告诉您哪些模块使用了其他模块,因此应该为您提供您所追求的信息。

Marc

#5


GExperts has a Project Dependencies tool. 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. 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.

GExperts有一个Project Dependencies工具。我在尝试追踪用过的单位之前使用过它。您无法在其中进行搜索,但可以将列表导出为CSV文件并在那里搜索。这也仅列出了使用部分中的内容。如果您有一个未使用的模块,它仍会显示。

#6


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. 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.
  2. CTRL-SHIFT-B打开对象浏览器。如果我没有记错的话,在这里你可以看到用过的单位。我不完全确定这种方法,也没有Delphi可用来验证它。

  3. Use Modelmaker; Modelmaker can give you a tree like view of all your unit dependancies. Look at the Visualizing existing code section for more information.
  4. 使用Modelmaker;模型制作者可以为您提供所有单位依赖性视图的树。查看可视化现有代码部分以获取更多信息。

#7


The easiest way is to compile program and check which .dcu was created by compiler. Make sure to setup compiler to create .dcu in a separate directory, for example 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).

最简单的方法是编译程序并检查编译器创建的.dcu。确保设置编译器以在单独的目录中创建.dcu,例如c:\ dcu。我创建了一个简单的实用程序,可以在编译器搜索路径(可以从.cfg,.dof或.bdsproject文件中读取)的目录中搜索每个.dcu文件的.pas。

#8


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,减少依赖性和消除生猪不仅有利于可执行的大小,当它升级到新版本的时候,它也是有益的。

#9


There is a (rather old) utility called UsgParse. It builds a treeview of all units referenced by a project.

有一个(相当古老的)实用工具叫做UsgParse。它构建了项目引用的所有单元的树视图。

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

binary: http://www.nexusdb.com/downloads/USGParse/USGParse.zip