Delphi中GUID相等检查中经典指针应用

 

 

type
  PGUID = ^TGUID;
  TGUID = packed record
    D1: LongWord;
    D2: Word;
    D3: Word;
    D4: array[0..7] of Byte;
    class operator Equal(const Left, Right: TGUID): Boolean;
    class operator NotEqual(const Left, Right: TGUID): Boolean;
    class function Empty: TGUID; static;
  end;
 
 IntegerArray  = array[0..$effffff] of Integer;
  PIntegerArray = ^IntegerArray;

function IsEqualGUID(const Guid1, Guid2: TGUID): Boolean;
var
  a, b: PIntegerArray;
begin
  a := PIntegerArray(@Guid1);
  b := PIntegerArray(@Guid2);
  Result := (a^[0] = b^[0]) and (a^[1] = b^[1]) and (a^[2] = b^[2]) and (a^[3] = b^[3]);
end;

 

遗留问题:Word 怎么转换成Ineger的? D2,D3:Word

@Guid1 内存存储结构是什么样的? 0xffff 0xff 0xff 0xff 转到PintegerArray后是什么样的? a^[1]=0xff 还是a^[1]=0xffff 为什么?

 

posted @ 2015-03-27 14:52  云水浮萍  阅读(213)  评论(0编辑  收藏  举报