(Note : only Delphi 3 - and perhaps 4 - makes the poor looking icons I mention in this paragraph, while Delphi 5 makes 32 by 32 icons that turn out properly, most of the time - for an example of what I mean try saving the 'Folder' icon in the Shell32.dll file using Delphi 5, and note that the save is not successful. The code included with this article is also unsuccessful, and the errors it makes are different, as you can tell by comparing the icon it produces with the erroneous icon produced by Delphi 5. There is code on this site that is capable of storing and retrieving the folder icons, and any other icons, although not as an icon file, but rather in a cache file -> Creating an Icon Cache file for a program.). If you have ever tried to save an Icon using Delphi you know that Delphi saves 16 by 16, 16 color icons. These display in an ugly manner when converted for display at 32 by 32 resolution. If you have investigated the Windows API you will see that while Icon loading functions are included there are no functions for saving icons. The code accompanying this article is an attempt to address this problem, and working things out was not a trivial matter. The save routine was based on what I learned about the icon file format and reading Icon files directly from disk. You can also find an explanation using a graphic explaining how a mask and a graphic are combined to create an image with transparency on the screen...
You can download the source code as a Delphi 3 / Delphi project here ... save_icon.zip (16 KB). You can also download the source as a textfile here ... save_icon_d3.txt Dephi 3 or save_icon_d5.txt Delphi 5
Once you are familiar with the Icon file format, saving an Icon is trivial. If you make your own Icon saving it to an icon file is trivial. However saving an existing Icon is not trivial for a number of reasons. I have found that to speed up the performance of a program I would like to cache icons rather than having to thrash a computer's disk drive reading the registry and then reading a file, and so on, and this experiement in saving an icon to an icon file is part of the process of learning to create this icon cache. What makes saving an icon difficult is that first, an Icon is returned with no palette. This can be solved through some reasoning. For example an icon with a pixelformat of 4 bits has 16 possible colors, and therefore assigning the icon the first 16 entries of the system palette seemed reasonable, and it worked. Whether it will always work is another question, but it has worked so far, and reason seems to suggest that it should. The second problem is that icons are returned with a pixel format of pfDevice, which makes it difficult to determine if an icon is using 16 or 256 colors. For this reason the routine as it is written only saves 32 by 32 4 bit 16 color icons. The API creates smaller icons by shrinking these larger icons, and almost every icon file I have seen on my computer contains one of these large icons in this color format (one icon was 24 bit true color). The routine could be set however to use GetSystemMetrics in the Windows API to find the width and height of an icon, and if it should be the case that it is not 32 by 32, to adjust the code accordingly. There should also be a way to find out what 'pfDevice' means on a particular computer and thus give the routine the ability to save other than 16 color icons.
A Unified Field Theory
![]()
The Unified Field Theory
is also available as a zip file -> unified.zip
Introduction :The Pioneer Effect and the New Physics. A brief description of the new physics required to explain the 'Pioneer Effect', which is the constant deceleration of space craft as they fly through space.

