[fpc-pascal] CreateGUID() [was Re: GUID code]

listmember listmember at letterboxes.org
Sat May 21 10:29:36 CEST 2005


Michael Van Canneyt wrote:

Hi Michael,

 >> I mean the whole code for CreateGUID() --one that does not
 >> use OS's GUID stuff.
 >
 > See Subversion, SysUtils unit, more specific uuid.pp in the
 > rtl/unix dir.

Thank you for the pointer.

Without creating incompatibility to the existing code (that of
Deplphi and Kylix included), might I suggest a little extension
to CreateGUID().

The reason I would like this is, there are timesone would
want to create GUIDs based on self supplied MAC numbers.

Here is a template of what I propose. If no one objects
to the idea, I can submit real code later.

---BEGIN PSEUDO CODE---

{These should be in Interface section of sysutils unit}
Type
   TMACNumber = Array [0..5] Of Byte;
   TUUIDCreationKind = (ucKernel, ucNIC, ucPseudoMAC);

{I could not find where PreferKernelUUID was defined,
but, with these changes we will not need it anymore}

Const
   NullMAC: TMacArray = [0,0,0,0,0,0];
   TUUIDCreationKind = (ucKernel, ucNIC, ucPseudoMAC);

{This should be in the Implemantation section}

Function CreateGUID(
   out GUID : TGUID;
   const UUIDCreationKind: TUUIDCreationKind = ucKernel;
   const MACNumber: TMACNumber = NullMAC
   ) : Integer;
begin
   case UUIDCreationKind of
     ucKernel: begin
       if not CreateKernelGUID(Guid) then
         if not CreateMACGuid(Guid) then
           GetRandomBytes(GUID,SizeOf(Guid));
       end;
     end;
     ucNIC: begin
       if not CreateMACGuid(Guid) then
         if not CreateKernelGUID(Guid) then
           GetRandomBytes(GUID,SizeOf(Guid));
     end;
     ucPseudoMAC: begin
      {Here comes code that uses MACNumber}
     end;
   end;
   Result:=0;
end;
---END PSEUDO CODE---

Cheers,
Adem




More information about the fpc-pascal mailing list