type TDate = class Mouth,day,Year:Integer; 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) LeapYear := True else if (Year mod 400 <> 0) LeapYear := False else LeapYear := True; end; 实现了这些定义之后,就可以这样调用它们: var ADay: TDate; begin //建立一个对象 ADay := TDate.create; //使用之 ADay.SetValue(1,1,2000); if ADay.LeapYear then ShowMessage('闰年:' + Inttostr(ADay.year)); //释放对象 ADay.free; end;
unit Myclock type TTimeFormat=(tfh24,tfh12); Tclock=class(Tclk) private FHour:Integer; FMinute:Integer; Fsecond:Integer; FTimeFormat:TTmineformat; public function SetTime(h,m,s:Integer):Boolean; function GetTime:TDateTime; Procedure TimeGo; published property TimeFormat:TTimeFormat read FTimeFormat write FTimeFormat end;
inplementation function TClock.GetTime:TDatetime; begin Result:EncodeTime(FHour,FMinute,FSecond,0); end ..... 创建实例 在你的单元中引用Myclock var aclock:tclock; begin aclock:=TClock.create;
TDate = class
Mouth,day,Year:Integer;
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)
LeapYear := True
else if (Year mod 400 <> 0)
LeapYear := False
else
LeapYear := True;
end;
实现了这些定义之后,就可以这样调用它们: var
ADay: TDate;
begin
//建立一个对象
ADay := TDate.create;
//使用之
ADay.SetValue(1,1,2000);
if ADay.LeapYear then
ShowMessage('闰年:' + Inttostr(ADay.year));
//释放对象
ADay.free;
end;
type
TTimeFormat=(tfh24,tfh12);
Tclock=class(Tclk)
private
FHour:Integer;
FMinute:Integer;
Fsecond:Integer;
FTimeFormat:TTmineformat;
public
function SetTime(h,m,s:Integer):Boolean;
function GetTime:TDateTime;
Procedure TimeGo;
published
property TimeFormat:TTimeFormat read FTimeFormat write FTimeFormat
end;
inplementation
function TClock.GetTime:TDatetime;
begin
Result:EncodeTime(FHour,FMinute,FSecond,0);
end
.....
创建实例
在你的单元中引用Myclock
var
aclock:tclock;
begin
aclock:=TClock.create;
delphi有面向對象編程的東西
類和實例肯定有啊