如何比较两个二维数组是否相等 - 回复 "阿拉丁" 的问题
一句话: 用 CompareMem 对比内存即可.
{对比静态数组} procedure TForm1.Button1Click(Sender: TObject); var arr1: array[0..3] of AnsiChar; arr2: array[0..3] of Byte; begin arr1[0] := 'A'; arr1[1] := 'B'; arr1[2] := 'C'; arr1[3] := 'D'; arr2[0] := 65; arr2[1] := 66; arr2[2] := 67; arr2[3] := 68; if CompareMem(@arr1, @arr2, SizeOf(arr1)) then ShowMessage('arr1 与 arr2 中的数据相同'); end; {对比动态数组} procedure TForm1.Button2Click(Sender: TObject); var arr1: array of AnsiChar; arr2: array of Byte; begin SetLength(arr1, 4); SetLength(arr2, 4); arr1[0] := 'A'; arr1[1] := 'B'; arr1[2] := 'C'; arr1[3] := 'D'; arr2[0] := 65; arr2[1] := 66; arr2[2] := 67; arr2[3] := 68; if CompareMem(arr1, arr2, SizeOf(arr1)) then ShowMessage('arr1 与 arr2 中的数据相同'); end; {多维数组也一样} procedure TForm1.Button3Click(Sender: TObject); var arr1: array[0..1, 0..1] of AnsiChar; arr2: array[0..1, 0..1] of Byte; begin arr1[0,0] := 'A'; arr1[0,1] := 'B'; arr1[1,0] := 'C'; arr1[1,1] := 'D'; arr2[0,0] := 65; arr2[0,1] := 66; arr2[1,0] := 67; arr2[1,1] := 68; if CompareMem(@arr1, @arr2, SizeOf(arr1)) then ShowMessage('arr1 与 arr2 中的数据相同'); end;posted on 2009-03-13 11:15 万一 阅读(5239) 评论(9) 编辑 收藏