I have just recently discovered a super easy way of adding custom icons to Delphi components. Traditionally you had to start from a rectangular bitmap of a specific size and color depth and then use Image Editor. This is documented in many places including Stackoverflow.

After a little bit of googling I have come across another Stackoverflow post that inspired my to give it a try and do it simpler. I wanted to have a big image and not square. Google image search with proper property rights filter typically sends me to wikipedia. Here is the link to high resolution image of the bike that I want to use as a icon for my component.

1) Save the image as a bitmap file, but the file is huge - 40 MB and 4819x2968 pixels. That's OK!

2) Create a new Delphi package project. To keep the steps simple let's stick with just one "designtime and runtime" package. Normally you should split your custom component into one designtime and one runtime package. Give the package whatever name. For example "PackageMySuperComponent".

3) Add to the package an empty unit for the custom component code. Save it for example as "uMySuperComponent.pas".

4) To keep it super simple just add a dummy "TMySuperComponent" declaration. Something like this:

unit uMySuperComponent;

uses System.Classes; type TMySuperComponent = class(TComponent) end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMySuperComponent]); end; end.

5) Save All. Now go to "Resources and Images" dialog in the "Project" menu. Add the bitmap to the package project, making sure that the bitmap identifier is the same as the name of the custom component. In our case this is "TMySuperComponent".

6) Now right-click on the package in the Project Manager and from the context menu select "Build" and then "Install". You should get the message that the component was successfully installed. Optionally restart the IDE.

7) Create a new visual Delphi app. In the Tool Palette you should find new "Samples" category with a new component with custom image.

It seems to be a not very documented, but I hope that this approach is OK to use and that you will find it useful!



Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy.

Start Free Trial   Free Delphi Community Edition   Free C++Builder Community Edition   Upgrade Today  

  • This is really not anything new. This approach is just a visual approach to the older technique of creating an RC/DCR file and linking it manually. Using the IDE's "Resources and Images" dialog manages the resource data for you, but the end result is still the same - the image gets linked as-is as a binary resource into the package binary using the component name as the resource name. That is how palette icons have always worked. The real enhancement is that newer IDE versions support non-standard sizes for palette images (16x16, 24x24, 32x32) and have done so for while now.
  • That's nice, I would like to have something like this "">gdj.graphicdesignjunction.com/.../icons-for-window-phone-4.jpg" in my button settings with customization as in StyleLookup section. Or choosing icon pack library as in Styles would be delicious on both C++ Builder & Delphi . So I can easily select the icon of my buttons. Styles and Icons should be separated and icons should have much more varieties as Glyp Icons before, i thought.