zoukankan      html  css  js  c++  java
  • Delphi GUID[2] 获取GUID值的方式

    Delphi GUID[2] 获取GUID值的方式

    源码:

    function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll' name 'CoCreateGuid';
    
    function CreateGUID(out Guid: TGUID): HResult;
    begin
      Result := CoCreateGuid(Guid);
    end;
    
    function GUIDToString(const GUID: TGUID): string;
    var
      P: PWideChar;
    begin
      if not Succeeded(StringFromCLSID(GUID, P)) then
        ConvertError(@SInvalidGUID);
      Result := P;
      CoTaskMemFree(P);
    end;  

    方式1:

    function GetGUID: string;
    var
      Guid: TGUID;
    begin
      CreateGUID(Guid);
      Result := GUIDToString(Guid);
    end;
    
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      ShowMessage(GetGUID);
    end;

    方式2:

    function Guid_Gen: ansistring;
    var
      s,gstr: string;
      i: longint;
    begin
      s := '0123456789abcdef';
        //8-4-4-4-12
      gstr := 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
      for i := 1 to length(gstr) do
      begin
        if gstr[i] = 'x' then
          gstr[i] := s[Random(16) + 1];
      end;
      Result:=gstr;
    end;
    
    procedure TForm1.BitBtn2Click(Sender: TObject);
    begin
       ShowMessage(Guid_Gen);
    end;
    

      

    创建时间:2021.05.25  更新时间:

    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你所有帮助,谢谢!
  • 相关阅读:
    python高级之操作数据库
    算法之矩阵计算斐波那契数列
    Mysql操作初级
    python高级之生成器&迭代器
    python高级之装饰器
    python高级之多进程
    python高级之多线程
    操作系统IO模型
    python高级之网络编程
    python高级之面向对象高级
  • 原文地址:https://www.cnblogs.com/guorongtao/p/14807159.html
Copyright © 2011-2022 走看看