22

In Delphi 7, an image editor program is included, which can read and write .dcr files, which are merely binary resource files (.res files) with a different extension, which by convention indicates that the .dcr file contains a compiled resource with named bitmap resources that have names corresponding to your component names (a bitmap resource named TMYCOMPONENT for a component named TMyComponent). These bitmaps are where the "icons" used to put an icon on the delphi component palette, and on your form or data-module when you drop a non-visual component on it, come from.

Fast forward 10 years to Delphi XE, and I am trying to make component icons using a bitmap file, and an RC file, and have that build to a .DCR file, as part of the Delphi IDE.

It should be simply a matter of adding an .Rc file and a declaration like this in the .dpk (package source) file, like this:

{$R mypackageicons.rc mypackageicons.dcr}

A sample .rc file containing a component icon:

 // COMPONENT ICON RESOURCES
 TMYCOMPONENT BMP "TMYCOMPONENT.BMP"

However I can not get this to work. It seems that you get some bizarre RLINK32 errors, and IDE crashes in borlandmm.dll, when I try it:

[DCC Error] E2161 Error: RLINK32: Unsupported 16bit resource in file "C:\temp\compicon\COMPONENTICONS.rc"
[DCC Fatal Error] F2084 Internal Error: AV21515155-W06000D07-1

The bitmap file in question is a simple 256 color bmp file size 24x24 pixels, and I have also tried 16 color bitmaps, with no luck. It seems to me that the ImageEdit program is the only way that I know of that I can use to create Delphi component icons.

What am I missing out on?

Update: The external tools are a nice solution for people who don't have access to the Delphi 7 image editor, and may in fact be superior, but I would prefer to do this using only what ships with Delphi, because it seems that it should be possible using just one {$R} declaration, a text file, and a bmp file made with paintbrush. Surely they didn't omit to make a way to make component icons, with this great big 1.5 gigabyte developer tool! .. update2: And there is a way; Rudy V. found it.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • 2
    Component resource files need to contain 24x24 pixel, 16 color VGA images. You don't have to give it the dcr extension; just add the`{$R YourRes.res}` to the package source file containing the `Register` procedure. – Ken White Aug 09 '11 at 18:08
  • I thought there was some reason it had to be named .dcr. – Warren P Aug 09 '11 at 18:10
  • @Ken `Register` procedures can be anywhere I think. The component resource needs to be in a .dpk? Or do I misunderstand? – David Heffernan Aug 09 '11 at 18:13
  • Open a .dcr file produced by ImageEditor in a resource editor and see what's there. You should be able to get the built in resource compiler to compile it for you. However, I never do that because the built in resource compiler doesn't properly handle 256px Vista icons, so I use my own build script for resources. Wouldn't you just know! – David Heffernan Aug 09 '11 at 18:26
  • IN this case, the RC file has only 1 bitmap file, a 16 color 24x24 BMP resource, and yet if I build it from the `{$R foo.rc foo.dcr}` directive, it's invalid somehow. – Warren P Aug 09 '11 at 18:33
  • 1
    I believe the resource should be of type 'BITMAP', not 'BMP'. – Sertac Akyuz Aug 09 '11 at 18:48
  • 1
    I tried that too. What's odd is that RES (DCR) files created with D7 Image editor create BMP entries, not BITMAP entries. – Warren P Aug 09 '11 at 18:51
  • Does your .dcr have the same name as the unit which does the registration of the component? It should have. In the project manager, if you add a .pas file to a package and there is a .dcr with the same name, in the same directory, it will automatically be included. My component installer (Delphi XE IDE) does the same. – Rudy Velthuis Aug 09 '11 at 18:54
  • 2
    I'm sure I've included .dcr files which did not have the same name as the unit that does registration. I'm sure I just included then in the dpk file. – David Heffernan Aug 09 '11 at 19:04
  • 1
    Compile with `>brcc32 mypackageicons.rc -fomypackageicons.dcr`, and include with `{$R mypackageicons.dcr}`. At least all will be with included tools. – Sertac Akyuz Aug 09 '11 at 19:24
  • Probably a graphic editor that you are using saves bitmaps without palette as 16- or 32-bit color bitmaps. So it does matter how many colors are actually in bitmap - resource compiler does not support these bitmap formats. – kludg Aug 09 '11 at 19:46
  • @Warren: The .dcr extension used to (pre-modern versions) auto-include the resource. This has changed in more recent versions (IIRC, D6/Kylix, but I could be wrong) to allow it to be in any resource file. Delphi 7 help mentions doing it with a non-dcr resource file, for instance. – Ken White Aug 09 '11 at 19:56
  • @David: Yes, the Register proc can be anywhere, but it also has to load the package. You're probably right, though; it should probably be in the package source. I use Register in a separate design-time package which registers the components contained in a runtime package, and the palette bitmaps are only needed at designtime, so I usually put them in the same place. – Ken White Aug 09 '11 at 19:58
  • This seems to work: add 'mypackageicons.rc' file to the project (this produces the 'mypackageicons.res' at compile time), then `{$R mypackageicons.res mypackageicons.dcr}` does not produce an .dcr but sets the icon for the component. Tested with a 256 color 'BITMAP' resource. – Sertac Akyuz Aug 09 '11 at 19:58
  • 1
    Sertak- put that in as an answer. But you don't get internal compiler AVs when you leave that in there and rebuild a few times? – Warren P Aug 09 '11 at 20:16
  • @Warren - I don't, but I can't test with DXE - D2007 here.. – Sertac Akyuz Aug 09 '11 at 20:22
  • See the update to my answer. It is possible to add a glyph bitmap and have it used, from inside the IDE. You'll have to create the bitmap with an external tool, though. – Rudy Velthuis Aug 09 '11 at 20:22
  • @Rudy; That's what I wanted. Perfect. I hadn't even noticed that menu item! – Warren P Aug 09 '11 at 20:46
  • The new resource editor dialog (also by Anders Melander, IIRC, but I might be wrong) was mentioned in delphi.non-tech a few times. I remembered that and found it. I had never used it before. – Rudy Velthuis Aug 09 '11 at 21:06
  • "16 color image" and "VGA image" are mutually exclusive – Premature Optimization Aug 10 '11 at 20:59
  • @Downvoter: That's directly from the D7 help file. Talk to Borland. – Ken White Aug 10 '11 at 22:13
  • @Ken White, what should I tell them? What you ripped that phrase out of context? Documentation talks specifically about Image Editor dialog (which is outside scope of OP's question). PS: what image editor means is 4bpp indexed colour, however i've seen higher colour depth(s) in BDS IDEs (no proof currently available). – Premature Optimization Aug 11 '11 at 01:45
  • Apparently i did not delete that project, BDS IDEs (at least since D207) are not very picky at component bitmap's pixel format. There are additionally 24bpp true and 8bpp indexed colour amongst those which component palette can display properly. – Premature Optimization Aug 11 '11 at 02:26
  • For the record, I extracted `imagedit.exe` and `imged32.dll` from the Delphi 7 CD media, and added a custom item in XE2's Tools menu for it. – Jerry Dodge Dec 29 '13 at 01:05

4 Answers4

22

I have used and had great success with:

Update

I just tried the following, in XE, and was successful.

  • I created a new component, TNewAnimate, in NewAnimates.pas.
  • I added TNewAnimate.pas to dclusr.dpk.
  • I added a bitmap (called TMRUComboBox.bmp, I just had that around anyway) using the Project → Resources and Images... dialog to the .dpk and gave it the name TNEWANIMATE.
  • I re-installed dclusr.dpk.

The source file for dclusr.pdk got a new entry {$R *.dres} (note the extension). I could see the TNewAnimate in the Samples palette with the glyph in TMRUComboBox.bmp.

I located dclusr.dres in the same directory as dclusr.dpk (which is normally under C:\Program Files, but not in my setup). I tried to open it with XN Resource Editor, but that refused to open it with a cryptic error message. It is not a normal .res file, it seems.

enter image description here

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • Do you mean in Delphi or in the editors? I must admit I haven't done any editing for a while anymore. I do fondly remember those editors. AFAIK, up to 256x256 icons with 32k colours are supported by both editors, but I could be wrong. Colin's as a little older, so it might not support all newer formats anymore. – Rudy Velthuis Aug 09 '11 at 17:46
  • I mean in Delphi. Not much use creating pretty icons that Delphi can't load. – David Heffernan Aug 09 '11 at 17:49
  • About the icons recogmized by Delphi: I don't know. I guess all kinds, these days. Hmmm... would be a nice question. – Rudy Velthuis Aug 09 '11 at 17:50
  • About Update: Nice find. But it seems there are some weird bugs in this new feature. Among them it seems easy to get the {$R *.dres} directive multiple times in your project source (.dpk) file, and they have to be removed in order to not crash. However, it works, I just did it, and it works fine, and unlike {$R item1 item2} never causes access violations. – Warren P Aug 09 '11 at 20:45
  • No problem, the pic peps it up a little . FWIW, the other dres entries have single quotes around the *.dres part, and that makes them invalid anyway. Must be a bug in the .dpk editor. I've had similar problems in previous Delphi versions. – Rudy Velthuis Aug 09 '11 at 21:04
  • 1
    I looks like it is broken in XE5 – fpiette Feb 20 '14 at 18:08
  • All this time and I've been using the ancient Image Editor from Delphi 7 for the later versions! – Jerry Dodge May 12 '17 at 19:08
6

Try Resource Editor. A nice replacement for old Image Editor.

kludg
  • 27,213
  • 5
  • 67
  • 118
  • Very nice tool and highly recommended, however I was more interested in how the low level text/compilation features should work. – Warren P Aug 09 '11 at 20:49
  • @Downvoter: Did you follow the link? From the opening section: "For now the resource editor is freeware. I have not decided what to do with it in the future. I may decide to turn it into a commercial product if I can find anyone willing to market it (I’m no good at that myself), I may decide to open source it or I may grow tired of it and just burn the disks - so to speak." It's at the top of the first page, last paragraph before the "Overview" heading. – Ken White Aug 11 '11 at 00:21
  • @KenWhite using `@Downvoter` sends notice to the actual downvoter? – PresleyDias May 09 '12 at 13:09
  • @PresleyDias, no. The user name of "Premature Optimization" at the time this was posted was "Downvoter Step Into The Light" or something like that; he's changed his name several times (and it's different now, in fact). – Ken White May 09 '12 at 13:50
  • 1
    For the record, I went to download this, but the download link returned `404 Not Found` – Jerry Dodge Dec 29 '13 at 00:09
  • "Note Please note that this is currently a blind page with no incoming links. Although there are no secrets here I request that you do not link to this page - yet." – dummzeuch Aug 24 '16 at 16:31
3

I have investigated the previous responses using Delphi XE5 upd2. Not much success. So I tried to build a new solution and found one derived from previous answers.

In short: 1. Create your bitmap using Windows Paint program. 2. Create a resource script file with the bitmap. 3. Compile the script with BRCC32 to produce the dcr file 4. Include the dcr file into the package source 5. Recompile/Install the package

To automate this, it is enough to add the BRCC32 command line into the package project "pre-build events". This way, you dcr file will be recreated before each build.

For a detailed description, see my blog at http://francois-piette.blogspot.be/2014/02/howto-create-dcr-file-for-your-delphi.html

fpiette
  • 11,983
  • 1
  • 24
  • 46
3

First add 'mypackageicons.rc' file to the project, this produces 'mypackageicons.res' at compile time (see related SO answer to the question "Including resource file in a project by .RC file rather than .RES file").

Also include {$R mypackageicons.res mypackageicons.dcr} to the component unit (or to the .dpk). This does not produce a '.dcr file', but sets the icon for the component.


Note that my test with a 'BMP' resource failed. I used 'BITMAP' as resource type.

Community
  • 1
  • 1
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • This worked for me, except that it also seems to sometimes cause access violations. – Warren P Aug 09 '11 at 20:48
  • @Warren - AFAIU there are alternatives as to how to include resources with D2009 and up. Perhaps not all of them get the same attention, who knows.. – Sertac Akyuz Aug 09 '11 at 21:13
  • I think that since this is supposed to work since 2007, it should get fixed in XE - I'll log it in QC. – Warren P Aug 09 '11 at 22:48