Interface Identification

An interface declaration can specify a globally unique identifier (GUID), represented by a string literal enclosed in brackets immediately preceding the member list. The GUID part of the declaration must have the form

['{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}']

where each x is a hexadecimal digit (0 through 9 or A through F). The Type Library editor automatically generates GUIDs for new interfaces. You can also generate GUIDs by pressing Ctrl+Shift+G in the code editor.

A GUID is a 16-byte binary value that uniquely identifies an interface. If an interface has a GUID, you can use interface querying to get references to its implementations.

The TGUID and PGUID types, declared in the System unit, are used to manipulate GUIDs.

type

PGUID = ATGUID; TGUID = packed record Dl: Longword; D2: Word; D3: Word;

end;

On the .NET platform, you can tag an interface as described above (i.e. following the interface declaration). However, if you use the traditional Delphi syntax, the first square bracket construct following the interface declaration is taken as a GUID specifier - not as a .NET attribute. (Note that .NET attributes always apply to the next symbol, not the previous one.) You can also associate a GUID with an interface using the .NET Guid custom attribute. In this case you would use the .NET style syntax, placing the attribute immediately before the interface declaration.

GUIDs are not required for interfaces in the .NET framework. They are only used for COM interoperability.

When you declare a typed constant of type TGUID, you can use a string literal to specify its value. For example, const IID_IMalloc: TGUID = '{00000002-0000-0000-C000-000000000046}';

In procedure and function calls, either a GUID or an interface identifier can serve as a value or constant parameter of type TGUID. For example, given the declaration function Supports(Unknown: IInterface; const IID: TGUID): Boolean;

Supports can be called in either of two ways if Supports(Allocator, IMalloc) then ...

or if Supports(Allocator, IID_IMalloc) then ...

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment