micheal
micheal

Reputation: 139

How can I use two dimensional dynamic array as a Function parameters?

hi i Have a problem when I use a two dimensional dynamic array. I use this: procedure ListDeleted(FilesList: array of array of Integer); Delphi give me compile error How can I fix it?

Upvotes: 3

Views: 2796

Answers (2)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43033

Define a custom type:

type
  TIntArray2 = array of array of Integer;

If you just read the parameter content in ListDeleted, use

 procedure ListDeleted(const FilesList: TIntArray2)

If the parameters are about to be modified internaly , use

 procedure ListDeleted(var FilesList: TIntArray2)

If the parameters are to be modified internally, but the modification should not be propagated to the caller, use

 procedure ListDeleted(FilesList: TIntArray2)

But notice that the last declaration (with no const nor var) will make a temporary copy of the array before calling ListDeleted, which is not a good idea for performance.

Upvotes: 3

mjn
mjn

Reputation: 36654

Declare the array type first, then use it in the parameter list

type
  T2DIntArr = array of array of Integer;

...

ListDeleted(FilesList: T2DIntArr);

Upvotes: 12

Related Questions