//给一个整型开放数组求和的函数
function MyFun(const arr: array of Integer): Integer;
var
i: Integer;
begin
Result := 0;
for i in arr do Result := Result + i;
end;
{测试1:}
procedure TForm1.Button1Click(Sender: TObject);
var
num: Integer;
begin
num := MyFun([1,2,3]);
ShowMessage(IntToStr(num)); {6}
end;
{测试2:}
procedure TForm1.Button2Click(Sender: TObject);
var
iArr: array of Integer;
i,x: Integer;
begin
SetLength(iArr, 10);
for i := Low(iArr) to High(iArr) do
begin
iArr[i] := i + 1;
end;
x := MyFun(iArr);
ShowMessage(IntToStr(x)); {55}
end;