Type Keyword
typeName
=Type declaration
; ... typeName
= typeType declaration
; typeName1
=Name2
; typeName
= (Identifier
, ...); typeName
=Expr1
..Expr2
; typeName
= ^Type
; typeName
= array[...] ofName
; typeName
= class ... end; typeName
= class of ...; typeName
= dispinterface ... end; typeName
= file ofType
; typeName
= function ...; typeName
= interface ... end; typeName
= object ... end; typeName
= procedure ...; typeName
= record ... end; typeName
= set ofOrdinal type
;
The type
keyword begins a type declaration, as it
does in standard Pascal.
If the type declaration begins with another occurrence of the
type
keyword, Delphi generates unique RTTI for the
type, even if the type is just a synonym for an existing type. It
also makes the type a distinct type with regard to
var
parameters.
A common convention in Delphi programs is to begin type names with the letter T, except for exception classes (which begin with E), interfaces (which begin with I), and pointer types (which begin with P).
A forward class declaration must be resolved in the same type block where it is declared. For example:
type TExample = class; // forward declaration TOther = class procedure Example(E: TExample); end; // Full class declaration without using another "type" keyword, // which starts a new type block. TExample = class procedure Example(Other: TOther); end;
A class declaration in the interface section of a unit must have definitions for all of the class’s non-abstract methods in the implementation section of the same unit.
type TSuit = (Diamond, Club, Heart, Spade); PCard = ^TCard; // pointer to TCard; TCard = record Suit: TSuit; Rank: 1..13; end; Deck = array[1..52] of TCard; TSuits = set of TSuit; TCardFunc = function(const Card: TCard): Integer; TCardProc = procedure(const Card: TCard); TCardMethodFunc = function(const Card: TCard): Integer of object; TCardMethodProc = procedure(var Card: TCard) of object; IGame = interface ['{6164F471-5E41-11D3-B1B6-00105AA9C2AD}'] procedure Play; procedure Draw(var Card: TCard); end; TGame = class(TInterfacedObject, IGame) public procedure Play; procedure Draw(var Card: TCard); end;