How to achieve smaller size of the executable?

Peter Perháč picture Peter Perháč · Jan 27, 2010 · Viewed 13.4k times · Source

Very recently I have come back to Delphi after a long pause and written a rather straightforward utility app my client requested to support an older release...

I know these days the size does not matter much, but it struck me as odd that the one-unit application, when compiled, amounted to 1'084'416 b executable. The one and only .pas unit I wrote is some 20.8k large, mostly because of the richness of the gui.

The uses clause is as follows:

uses
  Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, strutils,
  Dialogs, ADODB, DB, DBGrids, ExtCtrls, DBCtrls, StdCtrls, Grids, Menus,
  Buttons;

I wonder if there's any way I could reduce the size of the application to 300-400k or less?

Answer

Warren  P picture Warren P · Jan 27, 2010
  1. Did you do a debug or release build? (Make it release for smaller size, make sure optimization is on, debug information turned off)

  2. Did you turn off RTII (delphi 2010 and up) if not needed? (Smaller EXE sizes.)

  3. Number of units in your uses clause of your main unit, is not a good way to guess EXE size. Think of it this way: The VCL itself is one large amount of code, the Database Layer another, and the stuff you write is probably a very small percentage of the EXE size.

  4. To understand your executable size, try the JCL Project Analyzer, or read the MAP file that is produced when you turn on the Map option. This will tell you exactly what is inside your executable file.

It would be silly for various reasons, but you could get a smaller executable by using Delphi 7, for example. In the end when I make an application and I want to make it smaller, I look at how much time it would take, and how much effort to rebuild everything (such as with a vcl alternative) and I then say to myself, forget about it.