Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding unused (aka "dead") code in Delphi

Are there any tools that can determine if a function/procedure/method/entire class is used?

I've seen tools that can help a knowledgeable developer track down unused fragments of code (most are for languages other than Delphi) but most have a steep learning curve and/or require considerable digging to determine if a code fragment is used or not.

Delphi's smart linker purportedly does this to reduce the size of the final executable. Unfortunately what little information is given on the smart linker doesn't indicate a way to retrieve what was culled from the hurd.

Admittedly, even if it is possible to find out what the smart linker is eliminating it may be very conservative with its culling.

like image 565
Kenneth Cochran Avatar asked Nov 19 '10 16:11

Kenneth Cochran


2 Answers

Although clumsy and not global, you can examine the source code for the dots in the margin, as shown below. These are lines on which you can set breakpoints because the code hasn't been deadcode eliminated.

This happens, I believe, at the procedure level. I don't know a way to determine this at a less coarse level.

alt text

like image 96
RobertFrank Avatar answered Sep 21 '22 12:09

RobertFrank


This thread discusses removing unused units, and talks about tools like Icarus Pascal Analyzer. That tool will do all you need and more. How to "automatically" remove unused units from uses clause?

like image 23
Chris Thornton Avatar answered Sep 22 '22 12:09

Chris Thornton