home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 March
/
Chip_1999-03_cd.bin
/
zkuste
/
delphi
/
D234
/
AR_COMPS.ZIP
/
Days.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-01-24
|
6KB
|
154 lines
{##############################################################################
# Name: TDays - Quick # days in any month! #
# Author: Adrian Roberto Barbosa #
# Created: 11/11/1998 #
# UpDated: 12/02/1998 #
# Version: 2.1 #
# Description: This is very simple component to help you to obtain the #
# months' names and their numbers of the days. It's checks #
# if the year is the Leap Year and returns the name of month #
# in short or long forms. #
# Revisions: 1.0 beta Date: 11/11/1998 #
# 1.1 Date: 11/12/1998 #
# 1.2 Date: 12/02/1998 #
# Delphi: Delphi 2 (tested) or later (developed in Delphi 4) #
# Copyright: None!!! It's free, so comments are welcome... #
# Contact: adrianrb@netsite.com.br OR adrianrb@base.com.br #
##############################################################################}
unit Days;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TDays = class(TComponent)
private
{ Private declarations }
fNumDays : Word; // Temporary fields statement
fMonth : Word; // "
fYear : Word; // "
fLeapYear : Boolean; // "
fMonthName : String; // "
fShortName : Boolean; // "
procedure SetMonth(Value : Word); // procedures to manipulate
procedure SetYear(Value : Word); // properties and their fields
procedure SetShortName(Value : Boolean);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner : TComponent);override;
function GetLeapYear(Year : Word) : Boolean; // public functions
function GetNumDays(Month, Year : Word) : Word;
function GetMonthName(Month: Word; ShortName: Boolean): String;
published
{ Published declarations } // user interface properties
property NumDays : Word read fNumDays write fNumDays;
property Month : Word read fMonth write SetMonth;
property Year : Word read fYear write SetYear;
property LeapYear : Boolean read fLeapYear write fLeapYear;
property ShortName : Boolean read fShortName write SetShortName;
property MonthName : String read fMonthName write fMonthName;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TDays]);
end;
constructor TDays.Create(AOwner : TComponent);
var d,m,y : Word;
begin
inherited Create(AOwner);
DecodeDate(Now,y,m,d); // Get actual date to initialize component and
fMonth := m; // set their properties
fYear := y;
fNumDays := GetNumDays(fMonth, fYear);
fMonthName := GetMonthName(fMonth, fShortName);
end;
procedure TDays.SetMonth(Value : Word);
begin
if fMonth <> Value then
begin // Update month property
fMonth := Value; // and runs functions that
fNumDays := GetNumDays(fMonth, fYear); // returns the no. of days
fMonthName := GetMonthName(fMonth,fShortName); // in month and their mame
end;
end;
procedure TDays.SetYear(Value : Word);
begin
if fYear <> Value then // Update year propperty and runs
begin // the function that returns the no.
fYear := Value; // of days of month
fNumDays := GetNumDays(fMonth, fYear);
end;
end;
procedure TDays.SetShortName(Value : Boolean);
begin
if fShortName <> Value then // Update the ShortName property and
begin // runs the function that returns the
fShortName := Value; // name of month
fMonthName := GetMonthName(fMonth, Value);
end;
end;
function TDays.GetLeapYear(Year : Word) : Boolean;
begin
if (Year mod 4) <> 0 then
Result := False // Checks if Year is the Leap Year and
else // TRUE or FALSE
if (Year mod 100) <> 0 then
Result := True
else
if (Year mod 400) <> 0 then
Result := False
else
Result := True;
fLeapYear := Result;
end;
function TDays.GetNumDays(Month, Year : Word) : Word;
begin
Result := 0;
case Month of
1,3,5,7,8,10,12 : Result := 31; // Returns the no. of days to
4,6,9,11 : Result := 30; // month indicated, checking if
2 : begin // the year is the Leap Year
if GetLeapYear(Year) then
Result := 29
else
Result := 28;
end;
end;
end;
function TDays.GetMonthName(Month: Word; ShortName: Boolean): String;
begin
case Month of // Returns the month name, in short or long format
1 : if ShortName then Result := 'Jan' else Result := 'January';
2 : if ShortName then Result := 'Feb' else Result := 'February';
3 : if ShortName then Result := 'Mar' else Result := 'March';
4 : if ShortName then Result := 'Apr' else Result := 'April';
5 : if ShortName then Result := 'May' else Result := 'May';
6 : if ShortName then Result := 'Jun' else Result := 'June';
7 : if ShortName then Result := 'Jul' else Result := 'July';
8 : if ShortName then Result := 'Aug' else Result := 'August';
9 : if ShortName then Result := 'Sep' else Result := 'September';
10 : if ShortName then Result := 'Oct' else Result := 'October';
11 : if ShortName then Result := 'Nov' else Result := 'November';
12 : if ShortName then Result := 'Dec' else Result := 'December';
end;
end;
end.