Difference between revisions of "IDE Window: Find Unused Units"

From Free Pascal wiki
Jump to navigationJump to search
(New page: =IDE Dialog: Find unused units= ==How does it work== The function scans all used units of the current unit (all uses sections, not recursively) and checks if any interface definition of ...)
 
Line 17: Line 17:
 
*It does not evaluate expressions. So ''Something.Items.DoSomething'' are treated as three different identifiers. So it can mark an unit as needed, even though it is not.
 
*It does not evaluate expressions. So ''Something.Items.DoSomething'' are treated as three different identifiers. So it can mark an unit as needed, even though it is not.
 
*It only checks the current unit, not all units of a package or project.
 
*It only checks the current unit, not all units of a package or project.
 +
*Available since svn revision 19290 (lazarus 0.9.27).
  
 
==How to reach this dialog==
 
==How to reach this dialog==

Revision as of 00:44, 10 April 2009

IDE Dialog: Find unused units

How does it work

The function scans all used units of the current unit (all uses sections, not recursively) and checks if any interface definition of these units is mentioned in the current unit. It does no overload checks. It also checks if the used units has initialization/finalization sections.

You can select a set of units and let the IDE remove them from the uses sections of the current unit.

What is it good for

The compiler normally gives a hint if a unit is not used. But some units have an initialization section. For example the 'graphics' unit of the LCL registers a table of color names. The compiler therefore marks graphics as 'used' even though you might never use the color names. This dialog will show the difference and let the developer decide.

Limitations

  • The function does not check if an identifier was overloaded/redefined and thus is not really used. So it can mark an unit as needed, even though it is not.
  • It does not evaluate expressions. So Something.Items.DoSomething are treated as three different identifiers. So it can mark an unit as needed, even though it is not.
  • It only checks the current unit, not all units of a package or project.
  • Available since svn revision 19290 (lazarus 0.9.27).

How to reach this dialog

This dialog is available via source editor popup menu / Refactoring / Show unused units. You can also set a shortcut via the editor options / key mapping / Codetools commands / Remove unused units.

It is only available for pascal units.