windowsdelphiguiddelphi-10.4-sydneyclsid

How to create a CLSID (TGUID) in Delphi with hexadecimal values like in C++?


How to create a CLSID (System.TGUID in Delphi) with hexadecimal values, like in C++?

For example:

CLSID clsid = {0x12345678, 0x1234, 0x1234, {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}};

I tried:

var
  clsid: TGUID;
begin
  clsid := TGUID($12345678, $1234, $1234, ($12, $34, $56, $78, $90, $AB, $CD, $EF));
  end;

But I receive this error message:

[dcc32 Error]: E2029 ')' expected but ',' found

I suppose that these CLSIDs will be used with CoCreateInstance().

Then, what's the Delphi equivalent code from the C++ syntax above?


Solution

  • The definition of TGUID is as follows:

    TGUID = record
              D1: Cardinal;
              D2: Word;
              D3: Word;
              D4: array[0..7] of Byte;
            end;
    

    So the Delphi equivalent would be:

    clsid.D1:=$12345678;
    clsid.D2:=$1234;
    clsid.D3:=$1234;
    clsid.D4[0]:=$12;
    clsid.D4[1]:=$34;
    clsid.D4[2]:=$56;
    clsid.D4[3]:=$78;
    clsid.D4[4]:=$90;
    clsid.D4[5]:=$AB;
    clsid.D4[6]:=$CD;
    clsid.D4[7]:=$EF;
    
    
    clsid:=TGUID.Create($12345678,$1234,$1234,[$12,$34,$56,$78,$90,$AB,$CD,$EF]);
    

    Or at declaration:

    VAR
      clsid: TGUID = (D1:$12345678; D2:$1234; D3:$1234; D4:($12,$34,$56,$78,$90,$AB,$CD,$EF));
    

    (For inline variable declaration use := instead of =, of course.)