//方法 1: 共用內存
procedure TForm1.Button1Click(Sender: TObject);
var
bf: record b1,b2,b3,b4: Byte end;
i: Integer absolute bf;
begin
bf.b1 := $CC;
bf.b2 := $DD;
bf.b3 := $EE;
bf.b4 := $FF;
ShowMessageFmt('%x', [i]); //FFEEDDCC
end;
//方法 2: 位運算
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
i := $CC or ($DD shl 8) or ($EE shl 16) or ($FF shl 24); //不用括號也可
ShowMessageFmt('%x', [i]); //FFEEDDCC
end;
//方法 3: 使用函數
procedure TForm1.Button3Click(Sender: TObject);
var
i: Integer;
begin
i := MakeLong(MakeWord($CC,$DD), MakeWord($EE,$FF));
ShowMessageFmt('%x', [i]); //FFEEDDCC
end;
//方法 4: 從靜態數組...
procedure TForm1.Button4Click(Sender: TObject);
var
bs: array[0..3] of Byte;
P: PInteger;
begin
bs[0] := $CC;
bs[1] := $DD;
bs[2] := $EE;
bs[3] := $FF;
P := @bs;
ShowMessageFmt('%x', [P^]); //FFEEDDCC
end;
//方法 5: 從動態數組...
procedure TForm1.Button5Click(Sender: TObject);
var
bs: array of Byte;
P: PInteger;
begin
SetLength(bs, 4);
bs[0] := $CC;
bs[1] := $DD;
bs[2] := $EE;
bs[3] := $FF;
P := @bs[0];
ShowMessageFmt('%x', [P^]); //FFEEDDCC
end;