Previous: Self argument To the Table of Content Next: Open Arrays

- 2.2.13.14 -
TMT Pascal Language Description
Pascal Language Structure
OOP Extensions

Interface type

Interfaces are similar to objects, however they can be declared only in the outermost scope of a program or unit, and they do not implement their own methods. Thus the interface methods cannot be declared as virtual or override. An interface type declaration has the following format:
type InterfaceName = interface (AncestorInterface) [ '{GUID}' ]
    memberList
end;
where AncestorInterface and ['{GUID}'] are optional. The MemberList can include only methods. Unlike objects, fields are not allowed in the interface declaration. All members of an interface are always public (viability modifiers are not allowed).
Also interfaces have no constructors or destructors. They cannot be instantiated, except through objects that implement their methods. If no ancestor is specified, the interface is a direct descendant of IUnknown , which is defined in the System unit as follows:
type
  IUnknown = interface
     function QueryInterface (const iid: TIID;
                               var obj):LongInt; stdcall;
     function AddRef: Longint; stdcall;
     function Release: Longint; stdcall;
 end;
To be compatible with Delphi, an interface declaration can specify a globally unique identifier (GUID) which is represented by a string literal enclosed in brackets immediately preceding the member list.

The GUID part of the declaration must have the following format: [' {xxxxxxxx -xxxx -xxxx -xxxx -xxxxxxxxxxxx}'] The TGUID and PGUID types are declared in the System unit as follows:
type
  PGUID = ^TGUID;
  TGUID = packed record 
    D1: Longint;
    D2: Word;
    D3: Word;
    D4: array [0..7] of Byte;
  end;
  TIID = TGUID;
To declare a typed constant of type TGUID, one can use a string literal to specify its value. For example,
const
  IID_IMYINTERFACE: TGUID = '{3C2A92C2-8AE5-43AC-BEB8-1957FA47C30F}';
In function calls, either a GUID or an interface identifier can serve as a value or constant parameter of type TGUID.


Previous: Self argument To the Table of Content Next: Open Arrays
Self argument Table of Content Open Arrays

- 2.2.13.14 -