Sign in Join
Wiki copytemporary

CalLite: Flag days in Finland: what changed

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

OldNewLine
11![](/wiki-images/e/ed/Flag_days_in_Finland.png) [[CalLite|TCalendarLite]] is a lightweight calendar component. This demo shows how CalLite can be used to display flag days in Finland in the calendar as small icons
22
33## unit uFinlandFlagDays
44
55``` pascal
66unit uFinlandFlagDays;
77
88{$mode objfpc}{$H+}
99
1010interface
1111
1212uses
1313 Classes, SysUtils, CalendarLite, DateUtils;
1414
1515procedure CalendarGetFlagDaysInFinland( AMonth, AYear: Integer;
1616 var Holidays: THolidays);
1717
1818implementation
1919const
2020 SATURDAY = 6;
2121 SUNDAY = 7;
2222 FEBRUARY = 2;
2323 MARCH = 3;
2424 APRIL = 4;
2525 MAY = 5;
2626 JUNE = 6;
2727 JULY = 7;
2828 OCTOBER = 10;
2929 NOVEMBER = 11;
3030 DECEMBER = 12;
3131
3232function MothersDay(year:integer):integer;
3333var
3434 day : integer;
3535 a_date : TDateTime;
3636begin
3737 day := 7;
3838 repeat
3939 inc(day);
4040 a_date := EncodeDate(year, MAY, day);
4141 until DayOfTheWeek( a_date ) = SUNDAY;
4242 result := day;
4343end;
4444
4545function FathersDay(year:integer):integer;
4646var
4747 day : integer;
4848 a_date : TDateTime;
4949begin
5050 day := 7;
5151 repeat
5252 inc(day);
5353 a_date := EncodeDate(year, NOVEMBER, day);
5454 until DayOfTheWeek( a_date ) = SUNDAY;
5555 result := day;
5656end;
5757
5858function MidsummerDay(year:integer):integer;
5959var
6060 day : integer;
6161 a_date : TDateTime;
6262begin
6363 day := 20-1;
6464 repeat
6565 inc(day);
6666 a_date := EncodeDate(year, JUNE, day);
6767 until DayOfTheWeek( a_date ) = SATURDAY;
6868 result := day;
6969end;
7070
7171function MemorialDayWarDead(year:integer):integer; //memorial day for the war dead
7272var
7373 day : integer;
7474 a_date : TDateTime;
7575begin
7676 day := MothersDay(year);
7777 repeat
7878 inc(day);
7979 a_date := EncodeDate(year, MAY, day);
8080 until DayOfTheWeek( a_date ) = SUNDAY;
8181 result := day;
8282end;
8383
8484procedure CalendarGetFlagDaysInFinland( AMonth, AYear: Integer;
8585 var Holidays: THolidays);
8686begin
8787 ClearHolidays(Holidays);
8888 begin
8989 case AMonth of
9090 FEBRUARY: begin
9191 AddHoliday( 5, Holidays);//Birthday of the national poet JL Runeberg
9292 AddHoliday(28, Holidays);//Day of Kalevala
9393 end;
9494 MARCH: AddHoliday(19, Holidays);// Birthday of novelist and playwright
9595 // Minna Canth, Day of Equality
9696 APRIL: begin
9797 AddHoliday( 9, Holidays);// The day Mikael Agricola, also celebrated
9898 // as the Day of the Finnish language
9999 AddHoliday(27, Holidays);// National War Veterans' Day
100100 end;
101101 MAY: begin
102102 AddHoliday( 1, Holidays);// 1 May, Vappu, the Day of Finnish Labour
103103 AddHoliday( 9, Holidays);// Europe Day
104104 AddHoliday(12, Holidays);// Day of the Finnish Identity, birthday
105105 // of the statesman J V Snellman
106106 AddHoliday(MothersDay(AYear), Holidays); // Mother's Day
107107 AddHoliday(MemorialDayWarDead(AYear), Holidays);//Memorial day for
108108 //the war dead
109109 end;
110110 JUNE: begin
111111 AddHoliday( 4, Holidays);// Flag Day of the Finnish Defence Forces
112112 AddHoliday(MidsummerDay(AYear), Holidays);// Midsummer Day
113113 end;
114114 JULY: AddHoliday( 6, Holidays);// Birthday of the poet Eino Leino
115115 OCTOBER: begin
116116 AddHoliday(10, Holidays);// Birthday of the National writer
117117 // Aleksis Kivi, also celebrated as the
118118 // Day of Finnish literature
119119 AddHoliday(24, Holidays);// Day of the United Nations
120120 end;
121121 NOVEMBER: begin
122122 AddHoliday( 6, Holidays);// Finnish Swedish Heritage Day
123123 AddHoliday(FathersDay(AYear), Holidays);//Father's Day
124124 end;
125125 DECEMBER: begin
126126 AddHoliday( 6, Holidays);// Independence Day
127127 AddHoliday( 8, Holidays);// Birthday of the composer Jean Sibelius
128128 // also celebrated as the Day of Finnish
129129 // music
130130 end;
131131 end;
132132 end;
133133end;
134134
135135end.
136136```
137137
138138## unit unitFinlandFlagDays
139139
140140``` pascal
141141unit unitFinlandFlagDays;
142142
143143{$mode objfpc}{$H+}
144144
145145interface
146146
147147uses
148148 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, CalendarLite,
149149 Types, lcltype, uFinlandFlagDays;
150150
151151type
152152
153153 { TForm1 }
154154
155155 TForm1 = class(TForm)
156156 CalendarLite1: TCalendarLite;
157157 procedure CalendarLite1DrawCell(Sender: TObject; ACanvas: TCanvas; AYear,
158158 AMonth, ADay: Word; AState: TCalCellStates; var ARect: TRect;
159159 var AContinueDrawing: Boolean);
160160 procedure FormCreate(Sender: TObject);
161161 private
162162
163163 public
164164
165165 end;
166166
167167var
168168 Form1: TForm1;
169169
170170implementation
171171
172172procedure FlagOfFinland(var Bitmap: TBitmap);
173173const
174174 FFH = 11; // FinlandFlagHeight
175175 FFCH1 = 4; // FinlandFlagCrossH1
176176 FFCH2 = 7; // FinlandFlagCrossH2
177177 FFW = 18; // FinlandFlagWidth
178178 FFCW1 = 5; // FinlandFlagCrossW1
179179 FFCW2 = 8; // FinlandFlagCrossW2
180180begin
181181 Bitmap.Canvas.Pen.Color := clWhite;
182182 Bitmap.Canvas.Brush.Style:=bsSolid;
183183 Bitmap.Canvas.Brush.Color:= clWhite;
184184 Bitmap.Canvas.FillRect(0, 0, Bitmap.Width, Bitmap.Height);
185185 Bitmap.Canvas.Brush.Color:=RGBToColor(0, 47, 108) ;
186186 Bitmap.Canvas.FillRect(0,MulDiv(Bitmap.Height,FFCH1,FFH),
187187 Bitmap.Width,MulDiv(Bitmap.Height,FFCH2,FFH));
188188 Bitmap.Canvas.FillRect(MulDiv(Bitmap.Width,FFCW1,FFW),
189189 0,MulDiv(Bitmap.Width,FFCW2,FFW),Bitmap.Height);
190190end;
191191
192192{$R *.lfm}
193193
194194{ TForm1 }
195195
196196procedure TForm1.CalendarLite1DrawCell(Sender: TObject; ACanvas: TCanvas;
197197 AYear, AMonth, ADay: Word; AState: TCalCellStates; var ARect: TRect;
198198 var AContinueDrawing: Boolean);
199199
200200var
201201 Bitmap: TBitmap;
202202 Flagdays: THolidays;
203203begin
204204 CalendarGetFlagDaysInFinland(AMonth,AYear,Flagdays);
205205 if IsHoliday(aDay,Flagdays) and not (csOtherMonth in AState) then begin
206206 Bitmap := TBitmap.Create;
207207 try
208208 // Initializes the Bitmap Size
209209 Bitmap.Height := 11;
210210 Bitmap.Width := 18;
211211 FlagOfFinland(Bitmap);
212212 ACanvas.Draw(ARect.Left, (ARect.Top + ARect.Bottom - Bitmap.Height) div 2,
213213 Bitmap);
214214 inc(ARect.Left, Bitmap.Width + 2);
215215 // Not changing AContinueDrawing from its default value (true) means
216216 // that the day text is drawn by the built-in procedure into
217217 // the reduced rectangle
218218 finally
219219 Bitmap.Free;
220220 end;
221221 end;
222222end;
223223
224224procedure TForm1.FormCreate(Sender: TObject);
225225begin
226226 CalendarLite1.Languages := lgFinnish;
227227 CalendarLite1.StartingDayOfWeek := dowMonday;
228228 CalendarLite1.Date:=now;
229229end;
230230
231231end.
232232```
233233
234234## unitFinlandFlagDays.lfm
235235
236-``` pascal
236+``` lfm
237237object Form1: TForm1
238238 Left = 543
239239 Height = 278
240240 Top = 159
241241 Width = 426
242242 Caption = 'Flag days in Finland'
243243 ClientHeight = 278
244244 ClientWidth = 426
245245 OnCreate = FormCreate
246246 LCLVersion = '1.8.0.5'
247247 object CalendarLite1: TCalendarLite
248248 Left = 72
249249 Height = 200
250250 Top = 56
251251 Width = 274
252252 Constraints.MinHeight = 120
253253 Constraints.MinWidth = 120
254254 ParentColor = False
255255 TabOrder = 0
256256 TabStop = True
257257 Colors.TodayFrameColor = clGray
258258 Date = 42993
259259 DayNames = 'Su,Ma,Ti,ke,To,Pe,La'
260260 DisplayTexts = '"Tänään on",dd.mm.yyyy,Lomapäivät,"Lomapäiviä ei ole asetettu"'
261261 MonthNames = 'Tammikuu,Helmikuu,Maaliskuu,Huhtikuu,Toukokuu,Kesäkuu,Heinäkuu,Elokuu,Syyskuu,Lokakuu,Marraskuu,Joulukuu'
262262 MultiSelect = False
263263 StartingDayOfWeek = dowMonday
264264 WeekendDays = [dowSunday, dowSaturday]
265265 Languages = lgFinnish
266266 OnDrawCell = CalendarLite1DrawCell
267267 end
268268end
269269```
270270
271271## program flagdays_project
272272
273273``` pascal
274274program flagdays_project;
275275
276276{$mode objfpc}{$H+}
277277
278278uses
279279 {$IFDEF UNIX}{$IFDEF UseCThreads}
280280 cthreads,
281281 {$ENDIF}{$ENDIF}
282282 Interfaces, // this includes the LCL widgetset
283283 Forms, unitFinlandFlagDays, uFinlandFlagDays
284284 { you can add units after this };
285285
286286{$R *.res}
287287
288288begin
289289 RequireDerivedFormResource:=True;
290290 Application.Initialize;
291291 Application.CreateForm(TForm1, Form1);
292292 Application.Run;
293293end.
294294```
295295
296296---
297297*From the Free Pascal wiki, page "CalLite: Flag days in Finland", as it stood on 2019-10-24 after a change by Djzepi, 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).*

Back to history