Problem Source: http://www.cnblogs.com/del/archive/2009/03/21/1410030.html#1483614
{Convert tbytes to integer} procedure tform1.button1click (Sender: tobject); var BS: tbytes; {tbytes is the dynamic array of byte} I: integer; begin {it should be the same size as integer for conversion} setlength (BS, 4); BS [0]: = $10; BS [1]: = $27; BS [2]: = 0; BS [3]: = 0; {because tbytes is a dynamic array, its variable BS is a pointer. Therefore, it is first converted to pinteger} I: = pinteger (BS) ^; showmessage (inttostr (I); {10000} end; {It is easier to convert from bytes static array to integer} procedure tform1.button2click (Sender: tobject); var BS: array [0 .. 3] of byte; I: integer; begin BS [0]: = $10; BS [1]: = $27; BS [2]: = 0; BS [3]: = 0; I: = INTEGER (BS); showmessage (inttostr (I) ;{ 10000} end; {convert to custom structure} procedure tform1.button3click (Sender: tobject); Type tdata = packed record a: integer; B: word; end; var BS: array [0 .. 5] of byte; {the array should be consistent with the structure size} data: tdata; begin fillchar (BS, length (BS), 0); BS [0]: = $10; BS [1]: = $27; Data: = tdata (BS); showmessage (inttostr (data. a); {10000} end; {A member converted to the custom structure} procedure tform1.button4click (Sender: tobject); Type tdata = packed record a: integer; B: word; end; var BS: array [0 .. 3] of byte; Data: tdata; begin fillchar (BS, length (BS), 0); BS [0]: = $10; BS [1]: = $27; data. a: = INTEGER (BS); showmessage (inttostr (data. a); {10000} end;