Mega Code Archive

 
Categories / Delphi / Examples
 

Create a guid at runtime

You may need to create a GUID at runtime. One reason could be to simply have a unique number that identifies each workstation. By the way the last group of digits in the GUID generated on a computer is its network card number (if any is present). Delphi does not have the needed definitions, here they are: function CoCreateGuid (pGUID : TGUID) : longint; external 'OLE32.DLL'; procedure TForm1.FormCreate(Sender: TObject); var udtGUID : TGUID; lResult : longint; begin lResult := CoCreateGuid(udtGUID); // see definition of TGUID in Delphi's online help // udtGUID.D4 = network card's number end;