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?
Executable compression is any means of compressing an executable file and combining the compressed data with decompression code into a single executable. When this compressed executable is executed, the decompression code recreates the original code from the compressed code before executing it.
One reason executables can be large is that portions of the C++ runtime library might get statically linked with your program.
Having a self extracting executable larger than 4GB is on the extreme side, since there's a 4gb limit on Windows executable files like *.exe, *. dll etc. for PE32 and a 64-bit version PE32+ (applies to 32-bit and 64-bit versions).
You can try using KOL (Key Objects Library is a set of objects to develop power (but small) 32 bit Windows GUI applications using Delphi but without VCL). KOL allows to create very compact Windows32 GUI applications (starting from ~11K without compression - if suggested system units replacement used). The most of code is converted to built-in assembler.
Another option is use a exe compressor like UPX.
Did you do a debug or release build? (Make it release for smaller size, make sure optimization is on, debug information turned off)
Did you turn off RTII (delphi 2010 and up) if not needed? (Smaller EXE sizes.)
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With