tags:

views:

970

answers:

12

Hi. 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.

A: 

An executable can embed different size icons.

Check to make sure you have defined icons for the different sizes. Delphi might be pulling one at random if you don't have all sizes defined. This would explain why the button bar looks one way, and on the desktop it looks another.

Byron Whitlock
+5  A: 

From Delphi's Menu Bar select Project->Options

In the Project Options select Application

There you will see the Icon selected for your app.

You can change it there.

ChuckO
A: 

Hi ChuckO and Byron.

I don't want to add an icon to my application. I want to find out why the current icon is not shown properly. This problem appears ONLY if I used that VCL package I was talking about. I am 100% sure that somehow is related to that package.

"Delphi might be pulling one at random if you don't have all sizes defined".

In my entire life I haven't seen Windows to randomly pull an icon from computer's memory. NOTE: if somebody is pulling a random icons then for sure it is not Delphi, as the problem appears even if the application is not running. So I would rather say the compiler replaced the right icon with the wrong one or messed somehow the PE resource.

Actually, after I have looked inside the EXE with a PE tool, it shows the wrong icon into the "MAIN ICON" resource field. In this case I don't get from where Windows Explorer and Total Commander are taking the "good icon".

Probably both icons are included in EXE, but in the wrong (messed up) fields.

+3  A: 

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.

Rob Kennedy
A: 

Check the language id of your application and default language of OS. If these don't match then you can have a troubles with icons.

A: 

Hi Rob. Thanks a lot for your detailed answer.

I have made an experiment:

I remove EVERY single non-critical file from my project: DCR, RES, DCU, DSK... I keep only DPR, PAS and DFM. Then I rebuilt the program. When not running, the icon was ok. When running, the icon (in taskbar) was the wrong one (the one stolen from that control).

Another experiment:

I built brand new application. Icon ok. Then I added a control from that VCL library and instantly the icon got messed up (ok at non-runtime", and the wrong one at run time).

So, only when I am using that VCL (add one of its units to the uses clause), my icon gets corrupted. I will look with that PE tool again. Maybe is better than mine.

Please, do edit your question. Stackoverflow is not a message board.
Gamecat
A: 

Have you checked this on more than one machine? Windows is notorious for icon caching problems.

Will Dean
A: 

Hi Will Dean. I am using mainly Total Commander which don't have this problem usually.

Anyway, the problem is inside Delphi/compiler. Why it replaces the icon? In the empty application I created for test, the XN Resource Editor shows that “MAIN ICON” is the wrong icon. The incredible thing is that the "good" icon (default Delphi 7 icon) cannot be found in the resources.

Please, do edit your question. SO is not a message board.
Gamecat
A: 

Ok. Just to be sure, I reset Windows icon cache.

A: 

I have used a different PE resource explorer and it shows that the MAIN ICON is the good icon!!!!

So, two different programs are showing the MAIN ICON in two different ways. No wonder why Explorer and Commander shows different icons.

It looks like the compiler totally messed the PE header.

A: 

Check the language id of your application and default language of OS. If these don't match then you can have a troubles with icons. Andreik

Hi. I don't remember to set/change the language of my application. I don't even know where I can do that.

+1  A: 

Fixed. The RES file got corrupted (probably by the XN Resource Editor or Borland ImagEdit).

Such a waste of time :(