在各網站的文章里面,見復制數據的方法中,有move的,有system.copy的,而要實際應用中,這兩種方法,並不是很完美,會遇到一些問題,比如copy在記錄里面的復制時,編譯都過不去,而CopyMemory的功能,就相當強大.
要注意如果不是byte時,長度可能需要使用sizeof來參與計算
Buff,BuffCmdCrc16:array of Byte
SetLength(BuffCmdCrc16, 10);
一、復制10個byte
CopyMemory(@BuffCmdCrc16[0],@Buff[0],10);
從第11個 byte位追加,取數從第5個起,取8個byte 的長度。
CopyMemory(@BuffCmdCrc16[10],@Buff[5],8);
定義在Winapi.Windows中:
procedure CopyMemory(Destination: Pointer; Source: Pointer; Length: NativeUInt);
begin
Move(Source^, Destination^, Length);
end;
從定義看,也是調用了move,但是直接用move,可沒這么順心順手