var
Bs: array[0..1] of byte;
begin
Bs[0] := $AA;
Bs[1] := $01;
//W := $01AA;
W2 := TWordRec(Bs);
H := W2.Hi;
L := W2.Lo;
ShowMessage('1. ' + IntToHex(Word(Bs), 4) + '-' + IntToHex(H, 2) + '-' + IntToHex(L, 2));
end;
=================================================
Delphi SysUtils.pas 中的 Union:
{ Type conversion records }
WordRec = packed record
case Integer of
0: (Lo, Hi: Byte);
1: (Bytes: array [0..1] of Byte);
end;
LongRec = packed record
case Integer of
0: (Lo, Hi: Word);
1: (Words: array [0..1] of Word);
2: (Bytes: array [0..3] of Byte);
end;
Int64Rec = packed record
case Integer of
0: (Lo, Hi: Cardinal);
1: (Cardinals: array [0..1] of Cardinal);
2: (Words: array [0..3] of Word);
3: (Bytes: array [0..7] of Byte);
end;
function TThreadLocalCounter2.HashIndex: Byte;
var
H: Word;
begin
H := Word(GetCurrentThreadID);
Result := (WordRec(H).Lo xor WordRec(H).Hi) and 15;
end;
..............Author:
shenloqi Time: 2007-3-20 16:01