Delphi Base

WindSon

导航

delphi获得唯一ID字符串

//这是我三层开发中常用的一个函数,直接调用CreateSortID
uses System.Win.ComObj,System.RegularExpressions,System.StrUtils,System.SysUtils;

function CreateID(ll: Integer): string; // overload;
const
  pattern: string = '[-|{|}]';
var
  MyIDStr: string;
begin
  MyIDStr := CreateClassID;
  MyIDStr := TRegEx.Replace(MyIDStr, pattern, '');
  // MyIDStr := ansiReplaceStr(MyIDStr, '-', '');
  // MyIDStr := ansiReplaceStr(MyIDStr, '{', '');
  Result := AnsiRightStr(MyIDStr, ll);
end;

function CreateSortID: string;  
begin
  Result := FormatDateTime('yyyyMMddhhmmsszzz', now) + CreateID(13);
end;

 

posted on 2020-03-16 17:18  windsonvip  阅读(708)  评论(0编辑  收藏  举报