In the old days, Delphi was delivered with a simple image editor which let you draw your bitmap and create the DCR file. The last version which included that tool was Delphi 7 if memory serves me well.
Now, you have to use a "paint" program to build your bitmap. Any will do provided it is able to produce Windows bitmap file (BMP) with a 24x24 pixels image having 16 or 256 colors. Windows "Paint" is enough for that.
Then you must transform that bitmap into a DCR file which is easy using any "resource compiler" program. Delphi is delivered with one named BRCC32. A resource compiler produce a RES file.
A resource compiler takes a resource script as a source file (RC). This is a text file containing commands to describe the resource you want to build. There are many kind of resources that can be included in a resource file. Here we are only interested in a bitmap resource.
Assuming be are building a component whose class name is TDemoComponent and that the source code is in DemoComponent.pas, we need to create a DemoComponent.dcr resource file containing a bitmap resource named TDemoComponent. We thus need to create DemoComponent.bmp bitmap and DemoComponent.rc resource script.
TDemoComponent BITMAP "DemoComponent.bmp"
Then we run BRCC32 with the following command line:
brcc32 -fo"DemoComponent.dcr" "DemoComponent.rc"
The resulting file has to be included in the package source file (DPK) containing the component. This is done by adding a single line into the dpk:
Usually you add this line right after the existing line
Summary of required files:
|DemoComponent.pas||Component source code||You create this with Delphi|
|DemoComponent.bmp||Component bitmap||You create this with Windows Paint|
|DemoComponent.rc||Resource script||You create this with NotePad|
|DemoComponent.dcr||Binary resource file||You use BRCC32 to create it|
This works for VCL and FireMonkey components. Visual and non visual components.
It is likely that you want to automate the process. Easy! Just add the BRCC32 command shown above in your package project option. Add it to the "Build Events" for target "All configurations", "Pre-build events". That's it. Doing this way, your DCR file will be recreated at each build. This takes time but BRCC32 is blazing fast at compiling a so simple RC file. Whenever you change the bitmap, just recompile/install the package and the updated bitmap will be shown.
Follow me on Twitter
Follow me on LinkedIn
Follow me on Google+
Visit my website: http://www.overbyte.be
This article is available from http://francois-piette.blogspot.be