Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a GUID version 1 in Delphi?

Is there a way to generate GUID v1 (time-based) in Delphi 5? I found this function...

unit ComObj;
function CreateClassID: string;

But I'm not sure if it generates a time-based GUID. Also I know about this...

SysUtils.CreateGUID(newGUID);

... which calls the Windows API CoCreateGUID that produces the GUID version 4 (random).

like image 529
Denis Lolik Avatar asked Mar 03 '23 15:03

Denis Lolik


1 Answers

Similar to how CreateGUID is implemented - using UuidCreateSequential:

uses
  Windows;

function UuidCreateSequential(out guid: TGUID): Longint; stdcall; external 'rpcrt4.dll' name 'UuidCreateSequential';

function CreateGUID_V1(out Guid: TGUID): HResult;
begin
  Result := HResultFromWin32(UuidCreateSequential(Guid));
end;

I don't have Delphi 5 here so not sure if everything being used here was available 20 years ago.

like image 186
Stefan Glienke Avatar answered Mar 27 '23 17:03

Stefan Glienke