Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə224/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   220   221   222   223   224   225   226   227   ...   294
DelphiLanguageGuide

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 = ^TGUID;
    TGUID = packed record
        D1: Longword;
        D2: Word;
        D3: Word;
        D4: array[0..7] of Byte;
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}';
192


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

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   220   221   222   223   224   225   226   227   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin