type
className = class [abstract | sealed] (ancestorType)
memberList
end;
Methods appear in a class declaration as function or procedure headings, with no body. Defining declarations for
each method occur elsewhere in the program.
For example, here is the declaration of the TMemoryStream class from the
Classes
unit.
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;
TMemoryStream descends from TCustomMemoryStream (in the
Classes
unit), inheriting most of its members. But
it defines - or redefines - several methods and properties, including its destructor method,
Destroy
. Its constructor,
Create
, is inherited without change from TObject, and so is not redeclared. Each member is declared as private,
protected, or public (this class has no published members). These terms are explained below.
Given this declaration, you can create an instance of TMemoryStream as follows:
var stream: TMemoryStream;
stream := TMemoryStream.Create;
Dostları ilə paylaş: