[英]Delphi UUID generator
Delphi 是否有内置的东西来生成 UUID?
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.在CreateGuid()
调用各种 API 之一,具体取决于平台。 For example on Windows, it nowadays calls UuidCreate
.例如在 Windows 上,它现在调用UuidCreate
。
此外,如果您需要接口声明的 GUID,请在代码编辑器中按ctrl + shift + g以在插入符号处插入 GUID。
If you're using one of the latest version of Delphi, and include SysUtils, you can call TGuid.NewGuid
to generate a new guid.如果您使用的是最新版本的 Delphi,并且包含TGuid.NewGuid
,则可以调用TGuid.NewGuid
来生成新的 guid。
NewGuid
is actually implemented in a helper class for TGuid ( TGuidHelper ), which is declared in SysUtils. NewGuid
实际上是在 TGuid ( TGuidHelper ) 的帮助类中实现的,该类在 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.这个函数调用了 CreateGUID 方法(也在 SysUtils 中并且已经在 Mitch Wheat 的回答中提到过),它实际上是一个跨平台函数,它根据运行的平台调用不同的库。
Yes TGUID
, see this example是TGUID
,看这个例子
program Guid;
{$APPTYPE CONSOLE}
uses
SysUtils;
begin
WriteLn(TGUID.NewGuid.ToString());
end.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.