Types

Types are the fundamental building blocks of the Oxygene language.

There are four broad categories of types:

  • Predefined Simple Types are small and atomic types that are built into the language to represent the simplest of data: numbers, booleans, strings, and the like.

  • Standard Types are also defined by the language itself and build upon other types to form complex combinations, such as arrays, sequences, tuples or pointers of a given other type.

  • Custom Types are types not defined by the language, but by yourself or provided by base libraries or frameworks. Where standard types are universal in application, custom types usually serve a specific purpose.

  • Modified Types extend or modify the behavior of a regular type, or a reference to such a type. For example, a value type can normally not be nil, but the nullable version of that same type can.

Oxygene also has support for declaring types in special ways:

  • Generic Types are classes (or records and interfaces) where one or more of the other types that the class interacts with (for example to receive or return as a parameter from methods) is not well-defined, but kept generic. This allows for the class to be implemented in a fashion that it can work with or contain different type parameters. Only when a generic type is used, a concrete type is specified.

  • Partial Types are regular types that are declared and implemented across multiple source files – commonly to keep a large class easier to maintain, or because one part of the class is generated by a tool.

  • Mapped Types allow you to provide the definition of a type that will not exist at runtime, but merely map to a different, already existing type.

  • Type Extensions can expand an existing type with new methods or properties (but not new data), even if that type was originally declared in an external library.

Type Declarations

Custom types and aliases to existing types can be declared in the interface or implementation section of any source file, after a type keyword. Each type declaration starts with the type's name, followed by an equal sign (=) and followed by an optional visibility specifier and the details of the type declaration as specified in the individual custom type topics referenced above.

type
  MyType = public { type declaration goes here };

Type aliases can be declared by simply following the equal sign with the name of another type.

type
  Number = Integer; // "Number" now has the same meaning as "Integer"

Type Names

Every type in Oxygene can be referred to either by its short name (MyClass), or what is called a fully qualified name that includes a full namespace (MyCompany.MyProject.MyClass).

When declaring types with a simple name, the type will automatically be placed in the namespace that is declared at the top of the file. Alternatively, a fully qualified name can be provided in the declaration to override the namespace.

namespace MyCompany.MyProject

interface

type
  MyClass = class // full name will be MyCompany.MyProject.MyClass
  end;

  MyCompany.OtherProject.OtherClass = class // full name will be MyCompany.OtherProject.OtherClass
  end;

You can read more about namespaces here.