Name

Type Keyword

Syntax

type Name = Type declaration; ...
type Name = type Type declaration;

type Name1 = Name2;
type Name = (Identifier, ...);
type Name = Expr1..Expr2;
type Name = ^Type;
type Name = array[...] of Name;
type Name = class ... end;
type Name = class of ...;
type Name = dispinterface ... end;
type Name = file of Type;
type Name = function ...;
type Name = interface ... end;
type Name = object ... end;
type Name = procedure ...;
type Name = record ... end;
type Name = set of Ordinal type;

Description

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.

Tips and Tricks

  • 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 ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.