How can I keep the size of a Delphi application small when it has many TImage components?
delphi, timage
Solution
Don't put the images in the executable. Keep them in external files and load them at runtime.
This will require you to stop loading the images into the `TImage` controls at design-time and instead use dynamic code to load the image, and transfer to the `TImage` control. There are many advantages of doing so:
- You keep your executable down to a reasonable size, one that can fit in the virtual address space.
- You can use the most appropriate compression format for the images. If I recall correctly, a Delphi `TImage` will persists to a .dfm file in a very inefficient way. You can choose to use PNG or JPEG compression.
- Keeping the files external allows you to better managed them when developing. You can keep them as separate files in your revision control system. Storing images in .dfm files makes for painstaking updates when you need to change the images. You have to do lots of interaction with the IDE. Storing as files allows you to overwrite the file, and commit to the repository.
Problem
I want to make an application using Delphi. The problem is I am going to have a lot of `TImage` components in it - which will make the exe size extremely large. So far my exe is 20MB large and I have only completed the home page, by my calculations the exe alone will be more than 10GB in size - which is way too much. How can I make an app with hundreds/thousands of images and yet let the exe be small in size?