'Delphi: Main form icon not changing with application icon [duplicate]

I have a tray application that monitors a Windows service. Depending on the status of the Windows Service, I change the application icon to either a green, orange or red LED.

My default application icon is the red LED (Project -> Options -> Application -> Icons).

All the icons change except the icon of the main form, that does not change. The following icons does change:

  1. Tray icon enter image description here
  2. Taskbar icon when maximized enter image description here
  3. Icons of all other forms enter image description here

What do I need to do to get the main form icon to change?

I have even explicitly change the frmMain.Icon but that also did not work.

My code is simple and looks like this:

    {set the application icon}
    if FAppStatus = Error then
      ImageList.GetIcon(2, Application.Icon)
    else
    if FAppStatus = Warning then
      ImageList.GetIcon(1, Application.Icon)
    else
      ImageList.GetIcon(0, Application.Icon);
    frmMain.Icon := Application.Icon;

I have tried different BorderStyles but that made no difference. I also played with Application.MainFormOnTaskbar without success.

Moderator: Please note that this question is NOT about the taskbar icon.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source