7.2 Interface identification: A GUID

An interface can be identified by a GUID. This is a 128-bit number, which is represented in a text representation (a string literal):

[’{HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH}’]

Each H character represents a hexadecimal number (0-9,A-F). The format contains 8-4-4-4-12 numbers. A GUID can also be represented by the following record, defined in the objpas unit (included automatically when in DELPHI or OBJFPC mode):

PGuid = ^TGuid;  
TGuid = packed record  
   case integer of  
      1 : (  
           Data1 : DWord;  
           Data2 : word;  
           Data3 : word;  
           Data4 : array[0..7] of byte;  
          );  
      2 : (  
           D1 : DWord;  
           D2 : word;  
           D3 : word;  
           D4 : array[0..7] of byte;  
          );  
end;

A constant of type TGUID can be specified using a string literal:

{$mode objfpc}  
program testuid;  
 
Const  
  MyGUID : TGUID = ’{10101010-1010-0101-1001-110110110110}’;  
 
begin  
end.

Normally, the GUIDs are only used in Windows, when using COM interfaces. More on this in the next section.