开发者

Delphi UUID generator

开发者 https://www.devze.com 2022-12-20 14:34 出处:网络
Does De开发者_Go百科lphi have anything built-in to generate UUIDs?program Guid; {$APPTYPE CONSOLE}

Does De开发者_Go百科lphi have anything built-in to generate UUIDs?


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.


If you're using one of the latest version of Delphi, and include SysUtils, you can call TGuid.NewGuid to generate a new guid.

NewGuid is actually implemented in a helper class for TGuid (TGuidHelper), which is declared in SysUtils.

This function calls the CreateGUID method (also in SysUtils and already mentioned in the answer by Mitch Wheat), which is actually a cross platform function that calls different libraries depending on the platform it runs on.


Yes TGUID, see this example

program Guid;

{$APPTYPE CONSOLE}

uses
SysUtils;

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

精彩评论

暂无评论...
验证码 换一张
取 消