Delphi语言学习7-类和对象2011-12-121.类的声明格式
type
className = class [abstract | sealed] (ancestorClass)
memberList
end;
2.类的声明和使用
//定义
type TMemoryStream = class(TCustomMemoryStream)
private
FCapacity: Longint;
procedure SetCapacity(NewCapacity: Longint);
protected
function Realloc(var NewCapacity: Longint): Pointer; virtual;
property Capacity: Longint read FCapacity write SetCapacity;
public
destructor Destroy; override;
procedure Clear;
procedure LoadFromStream(Stream: TStream);
procedure LoadFromFile(const FileName: string);
procedure SetSize(NewSize: Longint); override;
function Write(const Buffer; Count: Longint): Longint; override;
end;
//使用
var stream: TMemoryStream;
stream := TMemoryStream.Create;
3.类的继承
//继承一个类
type TSomeControl = class(TControl);
//根类 TObject
type TMyClass = class
...
end;
//等价于
type TMyClass = class(TObject)
...
end;