Using D2010, I'd like to do something like this:
procedure SizeArray(var aArr: array of integer; aSize: integer);
begin
SetLength(aArr,aSize);
end;
But this fails to compile. Because my "aArr" parameter isn't a dynamic array, it's an open array parameter. And SetLength cannot be called on it. The only way I know of to force the parameter to be a dynamic array is to give it a type name, like so:
type
TIntArray = array of integer;
procedure SizeArray(var aArr: TIntArray; aSize: integer);
begin
SetLength(aArr,aSize);
end;
And now the code compiles. And it works fine, for the most part, but this fails:
procedure Test;
var
a : array of integer;
begin
SizeArray(a,5);
end;
Because types of actual and formal var parameters must be identical and the compiler doesn't recognize "array of integer" and "TIntArray" as identical types.
So, here's my question: Is there some way I can get the compiler to identify my var parameter as a dynamic array rather than as an open array so that the caller can declare a simple "array of integer" rather than some named type?
Thanks in advance.