Unit Calpnl

Classes

TCalenPnl - Record

Functions

Register -

Types

TDateType
TDayWidth
TPaintJob

Constants

BORDER
BUTTON_WIDTH
DAYS_IN_MONTH

Variables


Functions


procedure Register;


Types


TDateType = record
aYear : Word;
aMonth : Word;
aDay : Word;
end;

TDayWidth = (dw1Char, dw2Char, dw3Char);

TPaintJob = (All, Header, Dates);

Constants

BORDER = 2

Posted in the hope that I can repay a little of my enormous debt to those many unselfish people who have made my life easier with freeware and code snippets. -o0o- TCalenPnl, a freeware Calendar descended from TCustomPanel. The really hard work for this component was done by Robert Vivrette, and is adapted from his freeware TDateEdit form. I needed a panel-based Calendar, and adapted the CalPop code to suit. TCalenPnl retains all the properties of a TPanel, and adds a few more. Some of the interesting published properties are... ShowDate: Shows\Hides the buttons and 'MMMMM YYYY' display above the abbreviated day names at the top. The Months or Years can then be changed programmatically by ScrollBars or similar. DayWidth: Uses 1 to 3 characters (M, Mo, Mon) to define the day name. Font: Big deal! Actually, the point is that the Font can be changed (typically the size would be changed) when TCalenPnl is Resized (OnResize). OnDateChange: A centralized event that allows users to change Labels, ScrollBars, Graphs or ProgressBars when the CalendarDate property is changed, internally or externally. Some interesting Public properties... CalendarDate: A TDateTime property that you can read or write to programmatically. The fractional part of CalendarDate, i.e. the time, is not stored. WeekNumber: An integer representing the... Week number of the TCalenPnl.Year. DayOfYear: Integer value for days that have passed, in the current (CalendarDate) year. DaysInYear: Integer, can be either 365 or 366. It could have just as easily been Boolean (it calls the Boolean IsLeapYear protected Function), but it suited my project. .Day, .Month, .Year are all integer Public Properties. There is some repitition in the code, as Robert's CalPop relies on the date being changed only by the buttons, therefore only in increments of one. I required TCalenPnl to be able to be set by other controls, so there is some duplication. A really clever programmer, over a rainy weekend, could re-do the code to shrink it a touch. You may have to look closely at some of the code, as it has been written to prevent a user entering an invalid date, which can happen with a ScrollBar. If the date highlighted is 31 August, and the user scrolls to September, the CalendarDate.Day is reset to the DaysInMonth (ie, 30), to prevent an error. Shouldn't be a problem as it almost guarantees no errors, but be aware. If you use 'MMMM DD YYYY' format in your Win International settings, ie US users, then the example above would use August 31. In other words, the code is 'Internationalized', to that extent. While CalPnl.PAS and the CalPnl.DCR have been produced in Delphi 2.0, there is no reason why the .PAS would not work in 16 bit Delphi, apart from a few // comments. I considered a dynamic StartOfWeek, as some other calendar programmes offer, because it is culturally presumptuous of me to use Sunday as day 1. If you wish to modify the source, please do so, and send me a copy to re-post. If you have any criticisms or suggestions, please send them to me... Peter Crain Brisbane, Queensland. AUSTRALIA. Compuserve 100237,2735

BUTTON_WIDTH = 16

DAYS_IN_MONTH = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)


Variables