4

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

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
Denis Lolik
  • 299
  • 1
  • 4
  • 11
  • 1
    In the related question "[How to generate a version 1 Guid in .NET?](https://stackoverflow.com/questions/9411673)" recommended to use [UuidCreateSequential](https://learn.microsoft.com/en-us/windows/win32/api/rpcdce/nf-rpcdce-uuidcreatesequential) – zed Aug 01 '19 at 06:34

1 Answers1

7

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.

Stefan Glienke
  • 20,860
  • 2
  • 48
  • 102