应用场景
有两个字节数组,需要比较是否一模一样,包括比较元素的个数,一个函数搞定无需再手动处理
函数代码
function ByteArraysEqual(const B1, B2: array of Byte): Boolean;
var
I: Integer;
begin
Result := Length(B1) = Length(B2);
if Result then
begin
for I := 0 to High(B1) do
begin
if B1[I] <> B2[I] then
begin
Result := False;
Exit;
end;
end;
end;
end;
测试
procedure TForm1.FormCreate(Sender: TObject);
const
B1: array[0..2] of Byte=($01, $02, $03);
B2: array[0..4] of Byte=($01, $02, $04, $05, $06);
begin
if ByteArraysEqual(B1, B2) then
ShowMessage('123');
end;
···