Automated members have the same visibility as public members. The difference
is that Automation type information (required for
Automation servers) is generated for automated members. Automated members typically
appear only in Windows classes and is not recommended for Linux programming.
The automated reserved word is maintained for backward compatibility.
The TAutoObject class in the ComObj unit does not use automated.
The
following restrictions apply to methods and properties declared as automated.
· The types of all properties, array property parameters, method
parameters, and function results must be automatable. The automatable types are
Byte, Currency, Real, Double, Longint, Integer,
Single, Smallint, AnsiString, WideString, TDateTime,
Variant, OleVariant, WordBool, and all interface types.
·
Method declarations must use the default register calling
convention. They can be virtual, but not dynamic.
· Property declarations can include access specifiers (read and
write) but other specifiers (index, stored, default,
and nodefault) are not allowed. Access specifiers must list a method
identifier that uses the default register calling convention; field
identifiers are not allowed.
· Property declarations must specify a type. Property overrides are
not allowed.
The
declaration of an automated method or property can include a dispid
directive. Specifying an already used ID in a dispid directive causes an
error.
On Windows, this directive must be followed by an integer constant that specifies an Automation dispatch ID for the member. Otherwise, the compiler automatically assigns the member a dispatch ID that is one larger than the largest dispatch ID used by any method or property in the class and its ancestors. For more information about Automation (on Windows only), see Automation objects.
Private, protected,
and public members
自动化成员拥有与公共成员相同的可见度。不同的是,自动化类型信息(Automation type information)(必需自动化服务器)为自动化成员产生。自动化成员典型地出现在Windows类中,并且不被推荐于Linux编程。保留字automated用于维持向后(旧版本)的兼容性。单元ComObj中的TAutoObject类不使用保留字automated。
下列约束适用于作为自动化成员声明的方法和属性:
· 所有属性的类型,数组属性参数,方法参数以及函数结果等一定是可自动化的。可自动化的类型有Byte, Currency,Real,Double,Longint,Integer,Single,Smallint,AnsiString,WideString,TDateTime,Variant,OleVariant,WordBool,以及所有的接口类型。
· 方法声明必需使用缺省的register调用约定。它们可以是虚拟的(virtual),但不能是动态的(dynamic)。
· 属性声明可以包括访问说明符(read和write),但其他说明符(index,stored,default,nodefault)是不允许的。访问说明符必需列出一个使用了缺省的register调用约定的方法;域说明符是不允许的。
· 属性声明必需指定一个类型。属性覆盖是不允许的。
自动化方法或属性的声明可以包括dispid指示字。在dispid指示字中指定一个已经使用过的ID会导致错误。
在Windows中,该指示字必需紧随一个整数常量,该整数常量为成员指定了自动化调度ID(Automation dispatch ID)。否则,编译器会自动赋给该成员一个调度ID,该ID是一个比该类及其祖先类中用于任何方法或属性的调度ID中最大的一个还要大的整数值。有关自动化(仅适用于Windows)的更多信息,见自动化对象。