# 判断一个数组的长度用 Length 还是 SizeOf ?

var
arr1: array[0..9] of Char;
arr2: array[0..9] of Byte;
begin
ShowMessageFmt('%d,%d,%d,%d',[Length(arr1), SizeOf(arr1),
Length(arr2), SizeOf(arr2)]);
{显示结果: 10,10,10,10}
end;



const
arr1: array[0..9] of Integer = (1,2,3,4,5,6,7,8,9,10);
arr2: array[0..1, 0..3] of Integer = ((1,2,3,4), (5,6,7,8));
var
arr3: array[Boolean] of Integer;
arr4: array[Byte] of Integer;
begin
ShowMessage(IntToStr(Length(arr1)));    {10}
ShowMessage(IntToStr(SizeOf(arr1)));    {40}

ShowMessage(IntToStr(Length(arr2)));    {2}
ShowMessage(IntToStr(Length(arr2[0]))); {4}
ShowMessage(IntToStr(Length(arr2[1]))); {4}
ShowMessage(IntToStr(SizeOf(arr2)));    {32}

ShowMessage(IntToStr(Length(arr3)));    {2}
ShowMessage(IntToStr(SizeOf(arr3)));    {8}

ShowMessage(IntToStr(Length(arr4)));    {256}
ShowMessage(IntToStr(SizeOf(arr4)));    {1024}
end;



const
arr: array[0..1, 0..2, 0..3] of Integer =
(((1,1,1,1), (2,2,2,2), (3,3,3,3)), ((4,4,4,4), (5,5,5,5), (6,6,6,6)));
begin
ShowMessage(IntToStr(SizeOf(arr) div SizeOf(Integer))); {24}
end;


posted on 2008-04-23 22:26  万一  阅读(...)  评论(...编辑  收藏