Originale-mail to me for new edition

 

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

['{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}']

where each x is a hexadecimal digit (0 through 9 or A through F). On Windows, the Type Library editor automatically generates GUIDs for new interfaces; you can also generate GUIDs by pressing Ctrl+Shift+G in the Code editor (on Linux, you must use Ctrl+Shift+G).

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 = ^TGUID;

  TGUID = packed record

    D1: Longword;

    D2: Word;

    D3: Word;

    D4: array[0..7] of Byte;

  end;

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 ...

if Supports(Allocator, IID_IMalloc) then ...

 

Topic groups

 

See also

Interface types: Overview

Object interfaces: Overview

 

 

译文

 

接口标识

 

接口声明中可以指定一个全球唯一标识(globally unique identifierGUID),它表示为一个由方括号封装的串文本并且立即出现在成员列表的最前部。接口声明中的GUID部分必须具有如下形式:

['{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}']

这里的每个x是一个十六进制数字(09AF)。在Windows中,类型库(Type Library)编辑器自动为新的接口产生GUID;也可以在代码编辑器中通过按下Ctrl+Shift+G来产生GUID。在Linux中则必须使用Ctrl+Shift+G

一个GUID是一个16字节的二进制值,该值唯一标识了一个接口。如果一个接口有一个GUID,那么可以用接口查询来获得对其执行的引用。

TGUIDPGUID类型在System单元中声明,它们用于操作GUID

type

  PGUID = ^TGUID;

  TGUID = packed record

    D1: Longword;

    D2: Word;

    D3: Word;

    D4: array[0..7] of Byte;

  end;

声明一个类型为TGUID的类型常量时,可以用一个串文本指定其值。例如,

const IID_IMalloc: TGUID = '{00000002-0000-0000-C000-000000000046}';

在过程和函数调用中,GUID和接口标识中的任何一个都可以作为TGUID类型的值或常量参数。例如,对于如下给出的声明

function Supports(Unknown: IInterface; const IID: TGUID): Boolean;

Supports可以通过下列两种方法被调用:

if Supports(Allocator, IMalloc) then ...

if Supports(Allocator, IID_IMalloc) then ...

 

主题组

 

相关主题

接口类型:概述

对象接口:概述