Jump to content
Clément

Hunting a unit reference

Recommended Posts

Posted (edited)

Hi,

 

I'm compiling a project (Delphi XE) with several millions lines and hundreds of units.
Somehow a specific unit got called in that project, and I must discover which unit is dragging it in. It might be a direct reference or indirect reference (Since I'm a very lucky guy, it must be a deep indirect reference). In any case, I have to deal with it.
Is there any tool that can help me track a specific unit linkage into a project?

 

TIA,

Clément

Edited by Clément

Share this post


Link to post

Peganza is another possible tool to find out which unit that drags in another unit.

Share this post


Link to post

You can check the map file.

 

In case you are already using MMX, its Analyze Unit Dependencies feature might help, too. 

Share this post


Link to post
Posted (edited)

CnPack has a function to remove unused units.

  1. to check it is laborious
  2. it is not what you require

But a miracle can happen:classic_laugh:

Edited by Stano

Share this post


Link to post
6 hours ago, Clément said:

Is there any tool that can help me track a specific unit linkage into a project?

Rename that unit, then build.

  • Like 2

Share this post


Link to post
22 hours ago, Lars Fosdal said:

Peganza is another possible tool to find out which unit that drags in another unit. 

I installed the free edition, ran it, but could'nt figure out how to check the units... I need to spend some more time to figure out if it can help

Share this post


Link to post
22 hours ago, Uwe Raabe said:

You can check the map file. 

 

In case you are already using MMX, its Analyze Unit Dependencies feature might help, too. 

I'm using a map file. the unit is there, but I cannot track how it ended up in this project.

I wasn't able to install MMX under XE.

Share this post


Link to post
21 hours ago, Alexander Sviridenkov said:

Very nice tool! But it didn't display the unit I'm looking for. The unit is not directly linked in the project file, instead it is in a folder defined in the IDE environment. I would have to add folders to a list of folders to look for. Is it possible with the latest version you made available?

Share this post


Link to post
10 minutes ago, Clément said:

Very nice tool! But it didn't display the unit I'm looking for. The unit is not directly linked in the project file, instead it is in a folder defined in the IDE environment. I would have to add folders to a list of folders to look for. Is it possible with the latest version you made available?

 

Just do a find in files.

Share this post


Link to post
17 hours ago, Kas Ob. said:

Rename that unit, then build.

This is driving me nuts... I renamed the unit, the project stopped  compiling as expected, but I can track that unit down. I can see it there, still unable to figure out which unit brings it in.
I even removed the folder from the IDE environment. The project also stop compiling, but with this time with units it really needs. I am adding those one by one.
As I thought it would be simpler to track it down ( stupid me ), I was working in the production .DPR, I had to undo everything, to be able to release a patch to a customer... 🤪

This project uses a very old in-house library (pre-2000) that migrated from Delphi 4 up to XE.

Share this post


Link to post
Posted (edited)
8 minutes ago, Lajos Juhász said:

 

Just do a find in files.

I will instead create a new DPR project in the "root" , forcing a scan of all sub-folder, including the one I know this library is. My problem is tracking down which unit is dragging "this unwanted unit" in the project.
Once I find the "unit responsible for dragging it in the project", I have to assess the best way to remove it from the project. Hopefully removing it from a "uses" clause will be enough, but I don't feel that lucky

Edited by Clément

Share this post


Link to post
Posted (edited)

Why not put a break point in it and use the call stack to see who needs it since you found the unit.   Or comment out half the enums or settings in it. 

 

If it's only a dcu--view in a text editor.    

 

The graph tool does have a build order output that could in help placing a breakpoint when compiling when unit is renamed. 

Edited by Pat Foley
added suggestion

Share this post


Link to post

I witnessed such behavior, in few times was not a pas unit but in dcu file referring to some ghost unit that i don't have reference in the code.

And it was a removed referenced unit after refactoring, so searching for the name of needed unit will return no result, while the dcu still having the reference. 

 

Try to rename the folders with your DCU's, also when it dcu tracking then Process Monitor will show some extra information about this.

Share this post


Link to post
Posted (edited)
33 minutes ago, Clément said:

Very nice tool! But it didn't display the unit I'm looking for. The unit is not directly linked in the project file, instead it is in a folder defined in the IDE environment. I would have to add folders to a list of folders to look for. Is it possible with the latest version you made available?

Last version should show all files used in application, not only ones mentioned in .dpr.

It starts from .dpr units and recursively find all units listed in inteface and implementation sections. Of course IDE Library path and projects paths settings are used when scanning.

BTW it can extract interface and implementation units even if only .dcu is available.

Edited by Alexander Sviridenkov

Share this post


Link to post
22 minutes ago, Kas Ob. said:

I witnessed such behavior, in few times was not a pas unit but in dcu file referring to some ghost unit that i don't have reference in the code.

or opened in the IDE 😄 

Build outside.

Share this post


Link to post
2 hours ago, Alexander Sviridenkov said:

Last version should show all files used in application, not only ones mentioned in .dpr.

It starts from .dpr units and recursively find all units listed in inteface and implementation sections. Of course IDE Library path and projects paths settings are used when scanning.

BTW it can extract interface and implementation units even if only .dcu is available.

The unit I'm tracking does not appear in the graph.

If I remove the path or rename the unit the project doesn't compile.

I deleted all dcus from the library root to be sure only valid ".pas" files are compiled.

Share this post


Link to post

But use the "grep" tool on command line to check where the unit are related, in all files (in all disk if necessary 😉) ?

 

Share this post


Link to post
16 minutes ago, Clément said:

The unit I'm tracking does not appear in the graph.

If I remove the path or rename the unit the project doesn't compile.

I deleted all dcus from the library root to be sure only valid ".pas" files are compiled.

This is quite strange. Does unit map looks correct (all other units are present)?

 

Share this post


Link to post
33 minutes ago, Clément said:

If I remove the path or rename the unit the project doesn't compile.

I think i can pin point it !

 

Just remembered another situation when the project wasn't using specific 3rd party library library, namely AlphaSkins and acPng dcu kept popping in compiled while it wasn't referenced in that project, the project wasn't even using AlphaSkins but the standard VCL TImage, this happen on my IDE and my PC not the client (owner of the source), i solved it by simply disabling or removing that package form the IDE when working on that project.

 

Share this post


Link to post
Posted (edited)
4 hours ago, Clément said:

If I [...] rename the unit the project doesn't compile.

That is why I would rename the unit. When the project fails to compile, the error should occur in the unit that is "using" the unwanted unit. Note that it often requires a Build rather than just a Compile to locate the unit containing the reference.

Edited by JonRobertson

Share this post


Link to post
4 hours ago, Clément said:

If I remove the path or rename the unit the project doesn't compile.

Of course not, but you should execute a build and not compile it.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×