The
interface section of a unit begins with the reserved word interface and
continues until the beginning of the implementation section. The interface
section declares constants, types, variables, procedures, and functions that
are available to clients, that is, to other units or programs that use
the unit where they are declared. These entities are called public
because a client can access them as if they were declared in the client itself.
The
interface declaration of a procedure or function includes only the routine’s
heading. The block of the procedure or function follows in the implementation
section. Thus procedure and function declarations in the interface section work
like forward declarations, although the forward directive isn’t used.
The
interface declaration for a class must include declarations for all class
members.
The interface section can include its own uses clause, which must appear immediately after the word interface. For information about the uses clause, see Unit references and the uses clause.
Program structure and syntax:
Overview
Unit structure and syntax: Overview
Unit references and
the uses clause
Multiple and indirect
unit references
Unit structure and syntax: Overview
单元中,以保留字interface(含该保留字)开始,直到实现节开始,这之间的部分是接口节(不含保留字implementation,因为该保留字作为实现节的开始)。接口节用于声明常量、类型、变量、过程、函数等,这些声明对于其客户(就是使用了该单元的单元、工程、库、包等)是可用的。也就是说,对于那些使用了该单元的其他单元或程序,这些声明都是可以使用的。因为这些实体对于该单元的客户来说,可以访问客户自身声明的实体一样进行访问,因此可以称为公共(public)实体。
过程或函数的接口声明仅包括例程首部;过程或函数的块位于接口节之后的实现节中。因此接口节中的过程和函数声明也可以看作是向前声明,尽管并没有使用forward指示字。
类在接口节中的声明必需包括其所有类成员的声明。
接口节可以包括其自身的uses子句,但必需紧随保留字interface之后出现。关于uses子句的更多信息,见单元引用和uses子句。