Delphi UUID生成器

时间:2010-02-20 01:44:39

标签: delphi uuid

Delphi是否内置了生成UUID的内容?

4 个答案:

答案 0 :(得分:63)

program Guid;

{$APPTYPE CONSOLE}

uses
SysUtils;

var

Uid: TGuid;
Result: HResult;

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

在封面CreateGuid()下调用各种AP​​I之一,具体取决于平台。例如,在Windows上,它现在调用UuidCreate

答案 1 :(得分:32)

此外,如果您需要接口声明的GUID,请在代码编辑器中按 ctrl + shift + g 以插入GUID在插入符号。

答案 2 :(得分:4)

如果您使用的是最新版本的Delphi,并且包含SysUtils,则可以致电TGuid.NewGuid以生成新的guid。

NewGuid实际上是在TGuid(TGuidHelper)的帮助器类中实现的,它在SysUtils中声明。

此函数调用CreateGUID方法(也在SysUtils中,Mitch Wheat的答案中已经提到),这实际上是一个跨平台函数,根据运行的平台调用不同的库。

答案 3 :(得分:0)

private bool AllowEndSession = false; private bool ShutbownBlockReasonCreated = false; private System.Windows.Forms.Timer shutDownTimer = null; protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_QUERYENDSESSION: if (!AllowEndSession) { bool result = ShutdownBlockReasonCreate(this.Handle, "Cleaning Up/Doing stuff... Wait a sec"); shutDownTimer = new System.Windows.Forms.Timer(); shutDownTimer.Tick += (s, evt) => { ShutbownBlockReasonCreated = false; ShutdownBlockReasonDestroy(this.Handle); shutDownTimer.Enabled = false; shutDownTimer.Dispose(); this.Close(); }; shutDownTimer.Interval = 10000; shutDownTimer.Enabled = true; ShutbownBlockReasonCreated = true; m.Result = IntPtr.Zero; } else { m.Result = (IntPtr)1; } break; case WM_ENDSESSION: if (ShutbownBlockReasonCreated) { ShutdownBlockReasonDestroy(this.Handle); } m.Result = (IntPtr)1; break; default: base.WndProc(ref m); break; } } ,请参见此示例

buildscript {
    repositories {
        jcenter()
        google() // <--- Add this
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
    }
}

allprojects {
    repositories {
        jcenter()
        google() // <--- Add this
    }
}