Delphi UUID generator

Viewed 39018

Does Delphi have anything built-in to generate UUIDs?

4 Answers
program Guid;

{$APPTYPE CONSOLE}

uses
SysUtils;

var

Uid: TGuid;
Result: HResult;

begin
Result := CreateGuid(Uid);
if Result = S_OK then
   WriteLn(GuidToString(Uid));
end.

Under the covers CreateGuid() calls one of the various APIs, depending on the platform. For example on Windows, it nowadays calls UuidCreate.

Also, if you need a GUID for an interface declaration, hit ctrl+shift+g in the code editor to insert a GUID at the caret.

Yes TGUID, see this example

program Guid;

{$APPTYPE CONSOLE}

uses
SysUtils;

begin
  WriteLn(TGUID.NewGuid.ToString());
end.
Related