Delphi Tips Trick

For Newbie

Iklan Responsive Atas

LightBlog
Responsive Ads Here

Tuesday, 15 November 2011

Leap Year check with delphi



leap year
Leap Year check with delphi


Functions that can be used:


function IsLeapYear(Year: Word): Boolean;


Example of use:



if isLeapYear(2020) then ShowMessage('Yes') else ShowMessage('No');


You can create new functions to determine whether a leap year by TDate.
leapByDate function (const DT: TDate): Boolean;
var
   d, m, y: Word;
begin
   DecodeDate (DT, y, m, d);
   Result: = isLeapYear (y);
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   if leapByDate (DateTimePicker1.Date) then ShowMessage ('Yes') else
     ShowMessage ('Not');
end;

No comments: