Dispatch
interface types (Windows only)
Dispatch interface types define
the methods and properties that an Automation object implements through IDispatch.
Calls to methods of a dispatch interface are routed through IDispatch’s Invoke
method at runtime; a class cannot implement a dispatch interface.
A dispatch interface type
declaration has the form
type interfaceName =
dispinterface
['{GUID}']
memberList
end;
where ['{GUID}'] is optional and memberList
consists of property and method declarations. Dispatch interface declarations
are similar to regular interface declarations, but they cannot specify an
ancestor. For example,
type
IStringsDisp = dispinterface
['{EE05DFE2-5549-11D0-9EA9-0020AF3D82DA}']
property ControlDefault[Index: Integer]:
OleVariant dispid 0; default;
function Count: Integer; dispid 1;
property Item[Index: Integer]: OleVariant
dispid 2;
procedure Remove(Index: Integer); dispid
3;
procedure Clear; dispid 4;
function Add(Item: OleVariant): Integer; dispid
5;
function _NewEnum: IUnknown; dispid
-4;
end;
Dispatch interface methods (Windows
only)
Methods of a dispatch interface
are prototypes for calls to the Invoke method of the underlying IDispatch
implementation. To specify an Automation dispatch ID for a method, include the dispid
directive in its declaration, followed by an integer constant; specifying an
already used ID causes an error.
A method declared in a dispatch
interface cannot contain directives other than dispid. Parameter and
result types must be automatable, that is, they must be Byte, Currency,
Real, Double, Longint, Integer, Single, Smallint,
AnsiString, WideString, TDateTime, Variant, OleVariant,
WordBool, or any interface type.
Properties of a dispatch interface do not include access specifiers. They can be declared as readonly or writeonly. To specify a dispatch ID for a property, include the dispid directive in its declaration, followed by an integer constant; specifying an already used ID causes an error. Array properties can be declared as default. No other directives are allowed in dispatch-interface property declarations.
Automation objects (Windows only)
调度接口类型(仅适用于Windows)
调度接口类型定义了方法和属性,这些方法和属性由自动化对象通过IDispatch接口实现。对调度接口的调用在运行时要经过IDisoatch的Invoke方法;类不能实现调度接口。
调度接口类型的声明具有如下形式
type interfaceName =
dispinterface
['{GUID}']
memberList
end;
这里的 ['{GUID}'] 是可选的,memberList 由属性声明和方法声明组成。调度接口声明与规范的接口声明相似,但前者不能指定祖先。例如,
type
IStringsDisp = dispinterface
['{EE05DFE2-5549-11D0-9EA9-0020AF3D82DA}']
property ControlDefault[Index: Integer]:
OleVariant dispid 0; default;
function Count: Integer; dispid 1;
property Item[Index: Integer]: OleVariant
dispid 2;
procedure Remove(Index: Integer); dispid
3;
procedure Clear; dispid 4;
function Add(Item: OleVariant): Integer; dispid
5;
function _NewEnum: IUnknown; dispid
-4;
end;
调度接口的方法(仅适用于Windows)
调度接口的方法是调用Invoke方法(基于IDispatch实现)的原型。要为一个方法指定自动调度ID,需要在其方法声明中包括dispid指示字,并跟随一个整数常量;指定一个用过的ID将导致错误。
在调度接口中声明的方法不能含有除dispid指示字外的指示字。参数及结果类型必须是自动的,也就是说,它们必须是Byte、Currency、Real、Double、Longint、Integer、Single、Smallint、AnsiString、WideString、TDateTime、Variant、OleVariant、WordBool等类型或任何接口类型。
调度接口的属性不能包括访问说明符。它们可以被声明为只读的(readonly)或只写的(writeonly)。要为属性指定调度ID,需要在其属性声明中包括dispid指示字,并跟随一个整数常量;指定一个用过的ID将导致错误。数组属性可以被声明为缺省的(default)。此外,在调度接口的属性声明中不允许其他任何指示字。