Board index » delphi » Incompatabile Type 'Array' and 'Dynamic Array'

Incompatabile Type 'Array' and 'Dynamic Array'

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' "

Please tell me how to correct this error.
Thanks in advance,

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:Incompatabile Type 'Array' and 'Dynamic Array'


Quote
mteam2...@my-deja.com wrote:
> 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;
> [snip]
> The compiler gave me an error at this assignment, the error was:
> " Incompatabile type 'array' and 'dynamic array' "

Try declaring the parameter as follows:
function Run(const tblName:String;const aFields:array of const):String;

Regards,
Udo
--
Please reply to newsgroup. No PMs unless requested.

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

Re:Incompatabile Type 'Array' and 'Dynamic Array'


Im Artikel <20000418132339.09048.00001...@nso-cm.aol.com>, alangll...@aol.com
(AlanGLLoyd) schreibt:

Quote
>The other "gotcha" to watch for is that separately declared variables of the
>same declarative elements are not compatible

The compiler in fact does not do a "string compare", to determine whether two
data types "mean" the same word, but instead only determines, whether or not
both data types refer to exactly the same (unique) type declaration.

In other context the compiler is not so exact, e.g. it cannot distinguish
different range types of the same basic (range) type in overloaded procedures.

DoDi

Other Threads