Mason Wheeler
Mason Wheeler

Reputation: 84540

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?

Upvotes: 11

Views: 7257

Answers (9)

Francesca
Francesca

Reputation: 21640

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.

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
(source: gexperts.org)


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

Upvotes: 7

dummzeuch
dummzeuch

Reputation: 11217

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?

Upvotes: 6

Eric Grange
Eric Grange

Reputation: 6211

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.

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.

Upvotes: 1

Chris Hesik
Chris Hesik

Reputation: 481

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).

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.

Upvotes: 25

Michał Niklas
Michał Niklas

Reputation: 54292

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).

Upvotes: 1

Mark Elder
Mark Elder

Reputation: 4127

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.

Upvotes: 5

Gerry Coll
Gerry Coll

Reputation: 5975

There is a (rather old) utility called 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

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

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

Upvotes: 0

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58431

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. 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.

Upvotes: 3

marc_s
marc_s

Reputation: 754220

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.

Marc

Upvotes: 4

Related Questions