Delphi – My application icon is corrupted (problems in the compiler?)

delphiicons

The "Application Icon" of my application is wrong.

My application shows in taskbar a different icon than the classic Delphi icon. Instead is shows the icon of one of my VCL's. That specific VCL from which the icon was "stolen" is not used in my application but other VCL's in the same package are used.

Related info:
– The icon looks ok if I drag and drop my app on Desktop.
– The icon looks ok in Windows Commander when I put the cursor on it.
– The icon does not look ok in Windows Commander when I drag and drop it in "Button Bar". Conclusion: the icon is not accidentally changed at the runtime (the problem is there even if the application is not running).

I use Delphi 7. I disabled EurekaLog and FastMM just to be sure, and rebuild the application. The problem still persists. I have not even the slightest clue why the compiler inserts the wrong icon.
I really need some hints.
Thanks.

Best Answer

The icon configured in the IDE is inserted in the RES file for your project with the name MAINICON. If you have the {$R *.RES} line in your DPR file, then the project resource file gets linked to your application by the compiler.

The icon displayed by Explorer for your EXE file is whatever the first icon in your application is. The icons or sorted alphabetically. If Explorer is showing the wrong icon, then it's likely that you have linked additional icons to your application, and one of them has a name that comes before MAINICON. It might have a numerical name. (I have no idea how Windows Commander decides what icon to display.)

If some component or other unit used by your project has a resource file linked to it with the $R directive, then it will be included in your project. You don't have to make any specific reference to the icon, or even mention the component's class name anywhere in the code. The mere presence of a $R directive in a used unit is sufficient to have the entire resource file linked in. The compiler doesn't do any "smart linking" to remove unused resources because it has no way of detecting resource usage at compile time.

The common problem is that Explorer shows the wrong icon, but the program itself uses the right one. That's fixed by renaming the "wrong" icons to come after MAINICON. But you say your program is behaving the opposite way: Explorer (the desktop) shows the right icon and your program uses the wrong one, right?

One possibility is that the $R directive in your DPR file is missing or wrong. Delphi might be linking an old version of the file. Try deleting the RES file of your project. The IDE will re-create it when it sees that it's missing. At that point, reconfigure the icon in the project options. You might also have to reset the project's version number.

You should also check the layout of the resources in your compiled program. I don't recall whether Delphi comes with a resource viewer suitable for the task. You can try PE Resource Explorer. Things to consider: What are the names of all the icons in your project? What icon appears with the name MAINICON? What RES file do the other icons come from, and what unit links it in?

Finally, a note on terminology: VCL is the Visual Component Library, the set of components that comes with Delphi. You can't have "a" VCL. The things you install to the Tool Palette (nee Component Palette) and put on forms and data modules are components, not VCLs.

Related Topic