13 May 2011

Delphi Uses Cleanup

When you drop a VCL component on a Delphi form the Delphi IDE automatically adds the unit(s) required by the component to the interface section uses statement. If you later remove the component, the units are not removed from the uses statement. This causes the need to sometimes clean the uses statement of unused units.

The Delphi smart linker will ignore unused code so normally the presence of these "extra" units does not increase the size of the compiled program.

I generally copy the default Delphi uses clause

// for TForm
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

// for TDataModule
uses
SysUtils, Classes;

into the unit and comment out the original uses clause (in the interface section). Then I do save and Delphi will add all the units that the components on the form need. Next I add some missing units from commented block like ShellAPI e.t.c., for full compile, without errors.

from http://www.brenemanlabs.com
Post a Comment