Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 2-7-2020. The page as it is now.

Changing application Icon

pascal
unit main;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Image1: TImage;
    ImageList1: TImageList;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    FIndex: Integer;
    procedure ChangeIcon(const AIndex: Integer);
  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.ChangeIcon(const AIndex: Integer);
begin
  ImageList1.GetBitmap(AIndex, Image1.Picture.BitMap);
  Application.Icon.Assign(Image1.Picture.Graphic);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  FIndex := -1;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(FIndex);
  ChangeIcon(FIndex);
  if FIndex = ImageList1.Count - 1 then
    FIndex := -1;
end;

end.

From the Free Pascal wiki, page "Changing application Icon", as it stood on 2020-02-07 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.