diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-06-25 16:33:36 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-06-25 16:33:36 +0200 |
commit | 65897d65d4bcd2f6270a0e29c864d98f690a4caa (patch) | |
tree | c4ec95266769a7fdaf4a4227f42bf4f469f07571 /src | |
parent | f454e682b6f4fe632c18fba122417cf7a14e9f95 (diff) | |
download | fpGUI-65897d65d4bcd2f6270a0e29c864d98f690a4caa.tar.xz |
Calendar: adjust day if needed when new month is selected.
eg: if current day is 31, and we select February, adjust day
to 28 or 29 (last day of Feb).
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/fpg_popupcalendar.pas | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/gui/fpg_popupcalendar.pas b/src/gui/fpg_popupcalendar.pas index 51f86963..8840c682 100644 --- a/src/gui/fpg_popupcalendar.pas +++ b/src/gui/fpg_popupcalendar.pas @@ -237,6 +237,7 @@ type implementation uses + dateutils, fpg_scrollbar, fpg_constants; @@ -418,14 +419,20 @@ procedure TfpgPopupCalendar.SetDateElement(Index: integer; const AValue: Word); var lD, lM, lY: Word; lDate: TDateTime; + d: Word; begin if AValue > 0 then begin DecodeDate(FDate, lY, lM, lD); case Index of - 1: lD := AValue; - 2: lM := AValue; - 3: lY := AValue; + 1: lD := AValue; + 2: begin + lM := AValue; + d := DaysInAMonth(lY, lM); + if lD > d then // If original day value is larger than days in new month + lD := d; + end; + 3: lY := AValue; end; try lDate := EncodeDate(lY, lM, lD); |