Monday, September 5, 2011

Creating Small Size Exe File

This article is intended for Delphi programmers, at least for those who have been using delphi programs. But it is possible for those who want to learn Delphi programming.



If we create an empty form, it will result an exe file with size around 290 KB  using Delphi 5, 360 KB using delphi 7, and even bigger using delphi 2006. Although the current capacity of memory and hard drive is arguably more than enough, but if we just intend to create a simple program, such size would be too big, not to mention additional size from other components and must be distributed over the internet. So is there any solution for creating small size applications?

And the answer is ... the exe file could have been compressed with the application tools such as UPX, which could make the application smaller by half or more. But there are some weakness in programs compressor such as UPX. Another alternative is to directly use the functions of the windows API (Application Programming Interface), the resulting file is guaranteed to be small. But this programming is much more difficult and probably very time-consuming just to create a blank form. For Delphi programmers there are specific components which is very powerful, so that the resulting application is small, fast executing time as using the Windows API directly, maybe even more. This component is called KOL (Key Object Library). For those who have never heard of KOL, can be seen an article about this here.

Interested using this component?

The use of this component is different than other Delphi standard components. Once this component is installed (the same as the installation of other components) you will have to do these steps to create a program :

  1. Create a new project (File> New> Application)
  2. Save All Project (File> Save All) and let the unit named Unit1.pas and Project1.dpr
  3. Place KOLProject component (from KOL tabs already installed) in Form1
  4. Fill in the component Property projectDest KOLProject1 with Project name, for example MyPRogram
  5. Place a component on Form1 KOLForm
  6. Move / slide one component KOLProject or KOLForm to generate additional code in the source code
  7. Click Save All, then close all projects (Close All)
  8. Open the folder where the project file is stored, and delete all files named Project1 (Project1.cfg, Project1.dof, Project1.dpr and Project1.res)
  9. Open the project MyProgram.dpr and Compile or Run
  10. If rhese steaps are done correctly, the file will be generated as MyProgram.exe with the size about 22 KB

The resulting program does not have icons, but don't be worry, the icon can be added later. The size of 22 KB is much smaller than the standard components that reaches 360 KB. Even this size can still be reduced. Download additional components to suit sysdcu Delphi version used, and included in the Library path to the first order (in menu Tools> Options Enviromment). Then Compile / Run again. Then the resulting application will have size about  13.5 KB.

No comments:

Post a Comment