Re:Dynamic array as return type
Quote
Stark <starkwed...@virgilio.it> wrote in message
news:LFon9.6453$Fz.186107@news1.tin.it...
Quote
> I am declaring a dynamic array as a type:
> Type
> TMyArray = array of integer;
> Then I use the type as a return type in a number of functions in several
> units, like this:
> function GetValues: TMyArray;
> ........
> and I use the function: MyArrayValues:= GetValues; where MyArray is
> of type TMyArray.
> This is OK, apart from the fact that, wherever I use the function, I need
to
> include in the interface uses statement the unit name where the type is
> declared.
> So I tried to get rid of the type definition and use directly the "array
of
> integer" like this:
> function GetValues: array of integer;
> but this is not accepted. So, this is the question: Is there a way ? Is
> there another way to get back an array of values from a function ?
You can pass dynamic arrays as open array parameters (the declaration is,
confusingly enough, the same).
If you only intend to write to the array I would use the out modifier rather
than var like so.........
procedure GetValues(out Data: array of integer);
And call it like so.........
GetValues(MyArrayValues);
You can use the High and Low functions within the procedure, but you can't
change the array's length with SetLength.
Dave