Re:Incompatabile Type 'Array' and 'Dynamic Array'
Quote
In article <8dhb2b$34...@nnrp1.deja.com>, mteam2...@my-deja.com writes:
>I have the following function:
>function Run(const tblName:String;const aFields:array of String):String;
>Also, I declared a variable outside the function so that I can acess it
>in other functions. The variable is as follows:
>Myvar:array of String;
>Inside the Run function, I made the following assignment:
>Myvar := aFields;
>The compiler gave me an error at this assignment, the error was:
>" Incompatabile type 'array' and 'dynamic array' "
As the error message suggested, one variable is a Dynamic Array ie it can be
re-sized to a different number of parameter. The other (your function
parameter) is an Open Array, ie it can have any number of elements but the
number of elements cannot be changed. A formal open array parameter can be
accessed by element only, assignments to an entire open array aren't allowed,
although an entire open array parameter can be passed to another function or
procedure. You could allocate the elements of the formal open array parameter
individually and consecutively to your dynamic array.
The other "gotcha" to watch for is that separately declared variables of the
same declarative elements are not compatible ie :-
var
A : array[0..6];
B : array[0..6];
.. are not compatible. However
A, B : array[0..6] of integer; .. are compatible, and
type
TMyIntArray = array[0..6] of integer;
var
A : TMyIntArray;
B : TMyIntArray; .. are compatible.
It's a funny old world, isn't it <g>.
Alan Lloyd
alangll...@aol.com