A type
is essentially a name for a kind of data. When you declare a variable you must
specify its type, which determines the set of values the variable can hold and
the operations that can be performed on it. Every expression returns data of a
particular type, as does every function. Most functions and procedures require
parameters of specific types.
Object Pascal is a strongly typed language, which means that it distinguishes a variety of data types and does not always allow you to substitute one type for another. This is usually beneficial because it lets the compiler treat data intelligently and validate your code more thoroughly, preventing hard-to-diagnose runtime errors. When you need greater flexibility, however, there are mechanisms to circumvent strong typing. These include typecasting, pointers, variants, variant parts in records, and absolute addressing of variables.
Type compatibility and
identity: Overview
一个类型(type)实质上就是数据种类的一个名称。声明变量时必需指定其类型,这决定了变量能存储的值的集合(范围)以及能对变量执行的操作。每个表达式都返回一个具有特定类型的数据,函数也如此。大多数的函数和过程需要指定了类型的参数。
Object Pascal是增强类型的语言,它能区别多种数据类型并且不总是允许用一种类型替换另一种。这通常是有益的,因为这使得编译器能聪明地处理数据并彻底地更新代码,防止由硬性诊断导致的运行时错误。当需要更好的灵活性时,仍然有超越强行类型指定的机制,包括类型转换、指针、变体、记录种的变体部分、变量绝对寻址等。