// Add these units to your uses-section

uses
Graphics, Controls

{
Creates an TIcon object from a TBitmap.
Handy for dynamically updating your application’s icon.
I use it often to update my application’s tray icon.

}

function CreateIconFromBitmap(Bitmap: TBitmap; TransparentColor: TColor): TIcon;
begin
  with TImageList.CreateSize(Bitmap.Width, Bitmap.Height) do
  begin
    try
      AllocBy := 1;
      AddMasked(Bitmap, TransparentColor);
      Result := TIcon.Create;
      try
        GetIcon(0, Result);
      except
        Result.Free;
        raise;
      end;
    finally
      Free;
    end;
  end;
end;