Delphi中GUID相等檢查中經典指標應用

雲水浮萍發表於2015-03-27

 

 

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 為什麼?

 

相關文章