Search code examples
delphi

Selecting multiple dates from a calendar


Is there a way to select multiple dates in a calendar component?

I want the user to fetch records from a DB based on the selected dates, not from a range of dates between two dates, but the dates the user selects on a calendar.

Would one build an array of selected dates and loop through the array, or is there a SQL way to do this?

I would like to fetch records from multiple dates that can be selected from a history table, and those specifically selected dates are not necessarily in a range but at different dates of the month, eg one date could be on the first day of the month and another on the fifteenth of the month, and so forth. I want to build a report that calculates sales done for those specific dates.


Solution

  • The TCalendarView control (in the Tool Palette under Windows 10) has the ability you are asking for. I can not check earlier than Delphi 10.1 Berlin, but there it was present.

    With property SelectionMode = smMultiple You can select individual days and they are remembered in the property SelectedDates[]. Count of selected dates can be read from property SelectedCount.

    enter image description here