Passing a dynamic array in a parameter

This is what i have been trying:
 
type
   MyArray = array of integer;

function Test ( a : MyArray):boolean;
begin

end;

procedure DoTheTest;
   var
     b : array of integer;

begin
    Test(b);
end;

Open in new window


but i get the error E2010 Incompatible types: 'MyArray' and 'dynamic array'

What i want to do is pass the dynamic array as a pointer - its huge so i don't want a copy of it.
Paer ToernellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Just use the same type

procedure DoTheTest;
   var
     b : MyArray;

begin
    Test(b);
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimyXCommented:
Or the other way:
function Test ( a : array of integer):boolean;
begin

end;

procedure DoTheTest;
   var
     b : array of integer;

begin
    Test(b);
end;

Open in new window

0
jimyXCommented:
Also you can cast it:
type
   MyArray = array of integer;

function Test ( a : MyArray):boolean;
begin

end;

procedure DoTheTest;
var
  b : array of integer;
begin
  if Test(MyArray(b)) then
      //ShowMessage('Works');
end;

Open in new window

0
systanCommented:
I don't know how will you use the functions, so I just add some important lines before declaring the array.

function Test ( a : MyArray):boolean;
begin
SetLength(a, length_of_your_dynamic_array);  //first line <must>
...
end;
0
Ephraim WangoyaCommented:

You can use a pointer or a var parameter, either of these will send the address of the array
type
  PMyArray = ^TMyArray;
  TMyArray = array of Integer;

//Method 1
function Test(A: PMyArray):boolean;
begin

end; 

procedure DoTheTest;
var
  b : TMyArray;
begin
  Test(@b);
end;


//Method 2
function Test(var A: TMyArray):boolean;
begin

end;

procedure DoTheTest;
var
  b : TMyArray;
begin
  Test(b);
end;

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.