unit class1;
interface
implementation
type
TDate=class
private
Mouth,Day,Year:Integer;
public
procedure SetValue(m,d,y:Integer);
function LeapYear:Boolean;
end;
procedure Tdate.SetValue(m,d,y:Integer);
begin
Mouth:=m;
Day:=d;
Year:=y;
end;
function TDate.LeapYear:Boolean;
begin
if (Year mod 4 <>0) then
LeapYear:=False
else if (Year mod 100 <>0) then
LeapYear:=True
else if (Year mod 400 <>0) then
LeapYear:=False
else
LeapYear:=True;
end;
end.
=================================
unit example;
interface
uses
class1,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
ADay:TDate;
begin
ADay:=TDate.Create;
ADay.SetValue(12,3,1200);
if ADay.LeapYear then
ShowMessage('闰年:'+Inttostr(ADay.Year)+'-'+Inttostr(ADay.mouth)+'-'+Inttostr(ADay.Day));
ADay.Free;
end.