Sign in Join
Wiki copytemporary

Changing application Icon: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Changing application Icon

OldNewLine
1+``` pascal
2+unit main;
3+
4+{$mode objfpc}{$H+}
5+
6+interface
7+
8+uses
9+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
10+ ExtCtrls;
11+
12+type
13+
14+ { TForm1 }
15+
16+ TForm1 = class(TForm)
17+ Image1: TImage;
18+ ImageList1: TImageList;
19+ Timer1: TTimer;
20+ procedure FormShow(Sender: TObject);
21+ procedure Timer1Timer(Sender: TObject);
22+ private
23+ FIndex: Integer;
24+ procedure ChangeIcon(const AIndex: Integer);
25+ public
26+
27+ end;
28+
29+var
30+ Form1: TForm1;
31+
32+implementation
33+
34+{$R *.lfm}
35+
36+{ TForm1 }
37+
38+procedure TForm1.ChangeIcon(const AIndex: Integer);
39+begin
40+ ImageList1.GetBitmap(AIndex, Image1.Picture.BitMap);
41+ Application.Icon.Assign(Image1.Picture.Graphic);
42+end;
43+
44+procedure TForm1.FormShow(Sender: TObject);
45+begin
46+ FIndex := -1;
47+ Timer1.Enabled := True;
48+end;
49+
50+procedure TForm1.Timer1Timer(Sender: TObject);
51+begin
52+ Inc(FIndex);
53+ ChangeIcon(FIndex);
54+ if FIndex = ImageList1.Count - 1 then
55+ FIndex := -1;
56+end;
57+
58+end.
59+```
60+
61+---
62+*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](/wiki-contact).*
63+Category: Code Snippets

Back to history