From b0c6c6891cd339ce63606d6aeeb848d6dc895e35 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 14 Sep 2021 14:29:10 +0000 Subject: [PATCH] CalLite: Fix crash when moving from a month with 31 days to a month with less days by means of the months dropdown. Set version 0.3.8 for next OPM release. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8089 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/callite/callight_pkg.lpk | 9 +++++---- components/callite/demo1/CalLiteTest.lpi | 6 ++++-- components/callite/source/calendarlite.pas | 20 ++++++++------------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/components/callite/callight_pkg.lpk b/components/callite/callight_pkg.lpk index 735ca9a4f..2cf98168e 100644 --- a/components/callite/callight_pkg.lpk +++ b/components/callite/callight_pkg.lpk @@ -1,6 +1,6 @@ - + @@ -11,9 +11,9 @@ - - - + + + @@ -21,6 +21,7 @@ + diff --git a/components/callite/demo1/CalLiteTest.lpi b/components/callite/demo1/CalLiteTest.lpi index ea653dbdd..3f154406c 100644 --- a/components/callite/demo1/CalLiteTest.lpi +++ b/components/callite/demo1/CalLiteTest.lpi @@ -1,11 +1,13 @@ - + + + + - <ResourceType Value="res"/> <UseXPManifest Value="True"/> diff --git a/components/callite/source/calendarlite.pas b/components/callite/source/calendarlite.pas index fa7cc02d8..8695899fa 100644 --- a/components/callite/source/calendarlite.pas +++ b/components/callite/source/calendarlite.pas @@ -1326,12 +1326,11 @@ begin end; procedure TCalDrawer.GotoMonth(AMonth: word); -var - d: TDate; begin - if not TryEncodeDate(FThisYear, AMonth, FThisDay, d) then // Feb 29 in leap year! - d := EncodeDate(FThisYear, AMonth, FThisDay); - FOwner.Date := d; + if (AMonth < 1) or (AMonth > 12) then + exit; + FThisDay := EnsureRange(FThisDay, 1, DaysInAMonth(FThisYear, AMonth)); + FOwner.Date := EncodeDate(FThisYear, AMonth, FThisDay); end; procedure TCalDrawer.GotoToday; @@ -1340,12 +1339,11 @@ begin end; procedure TCalDrawer.GotoYear(AYear: word); -var - d: TDate; begin - if not TryEncodeDate(AYear, FThisMonth, FThisDay, d) then // Feb 29 in leap year! - d := EncodeDate(AYear, FThisMonth, FThisDay); - FOwner.Date := d; + if (FThisMonth < 1) or (FThisMonth > 12) then + exit; + FThisDay := EnsureRange(FThisday, 1, DaysInAMonth(AYear, FThisMonth)); + FOwner.Date := EncodeDate(AYear, FThisMonth, FThisDay); end; procedure TCalDrawer.LeftClick(APoint: TPoint; Shift: TShiftState); @@ -1922,8 +1920,6 @@ begin item.Tag := y; if y = FCalDrawer.FThisYear then item.Checked := true; - if (FCalDrawer.FThisDay = 29) and (FCalDrawer.FThisMonth = 2) and not IsLeapYear(y) - then item.Enabled:= False; Add(item); end; end;