Setting EXE icon in Delphi 7
Asked Answered
M

3

10

I'm trying to customize the icon that shows in Windows Explorer and in Desktop shortcuts for my Delphi application.

In the Delphi 7 IDE, I have loaded the desired icon in the Application tab of the Project Options dialog. It shows my desired icon as a graphic.

I didn't think it was necessary, but I also set my icon as the TMainForm Icon property.

However, the resulting EXE still shows the default D7 icon. What am I missing?

Maritime answered 30/5, 2009 at 20:21 Comment(3)
"still shows the default D7 icon" where?Crake
@Nick: Like the question says, in Windows Explorer and Desktop shortcuts? <g>Chard
"I didn't think it was necessary, but I also set my icon as the TMainForm Icon property." - this is not something to do any more. Remove the form specific ones, or it causes problems in Vista or something (can't remember details, but I fell over it).Vondavonni
M
5

I found it after more hunting. I created a new project by copying an existing project from another folder. I forgot to change the program name at the top of the DPR file to match the name of the new project. Somehow, if a wrong name is used there, it prevents the icon from being changed in the generated EXE file...

Maritime answered 30/5, 2009 at 20:34 Comment(4)
The app's icon is stored in the .res file, as an icon resource named MAINICON.Amphistylar
@Stijn: No, he shouldn't. The answer may be useful to someone else in the future. Answering your own questions is covered in the SO FAQ - perhaps you should read it.Chard
@tim11g: could you edit your answer to be more explicit regarding what you learned was the problem, and how it can be fixed (without creating a new project)? As is, this answer is not clear. +1 to Ken - questions and CLEAR answers need to be retained.Serialize
@Argalatyr: I'm not sure exactly how or why it affects the ability to set the icon, but the issue was the Program name in the .DPR file. Since I copied the project from a similar project, the old project name was at the top of the DPR. The project filename has been changed to NewProject.DPR, but inside NewProject.DPR, the first line was "program OldProject;". That inconsistency seems to break something. Fixing it is as simple as opening the DPR file and changing the line "program OldProject;" to be "program NewProject;"Maritime
G
3

When you assign an icon to an application, the icon will be embedded in a .res file named identical to the program name (the name mentioned in the first line of the .dpr file). When you change the program name in the .dpr file, delphi creates a new .res file with the new program name and looks for the icon resource in the new res file and finds none, and hence uses the default icon (or a rectangular white box). The old res file which carries the icon resource will no longer be used. In summary, if you change the program name, you will have to re-assign the icon.

Gainer answered 8/10, 2011 at 15:10 Comment(0)
W
2

Maybe the icon cache needs to be deleted. There are many pages about this problem, this link might be useful: http://smallvoid.com/article/windows-icon-cache.html

Winona answered 30/5, 2009 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.