Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Xorcist

How would I go about....

This topic is 6085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

passing a multidimensional array to a function or procedure if I didn''t know the how the array was defined or declared (other than the base type)? In other words, to basically write a third party utility for programmers, that would say take any two dimensional array of integers and set the each element to zero. Keep in mind I have no type to associate my array with, nor do I know how the programmer implemented it. Is there a way to do this in Delphi, pointers maybe? I''ve been searching for a way to do this for a while now... and well I''m still searching.

Share this post


Link to post
Share on other sites
Advertisement
If it is for Delphi programmers only, then you can use the Low() and High() functions to give you the upper and lower bounds of the array.

I'm not sure if this will work (it's off the top of my head)...

procedure ZeroArray(Data: array of array of Integer);
var
k, j: Integer;
begin
for k := Low(Data) to High(Data) do
begin
for j := Low(Data[k]) to High(Data[k]) do
begin
Data[k, j] := 0;
end;
end;
end;

Hint: Never use i as an array index when providing sample code on this forum. The forum software thinks it means italics.

Steve 'Sly' Williams   Monkey Wrangler  Krome Studios
turbo game development with Borland compilers

Edited by - sly on November 18, 2001 5:57:09 PM

Share this post


Link to post
Share on other sites
See that''s just it, that doesn''t work. I''ve tried passing a two dimensional array parameter using array of array of but it won''t let you. It generates the following error:

Identifier expected but ''ARRAY'' found

Open array parameters seem to only work for single dimension arrays, multidimensional arrays always want a specific user defined type. Which is where I run into my problem. I mean if I just used array of rather than array of array of I get an error during any access or assignment within the procedure with the compiler telling me I need an array type? They just couldn''t make this easy could they...

AAAAAAAAAARRRRRGGGGGGGGGGGGHHHHHHHH!!!!!!!!!!!!!

Share this post


Link to post
Share on other sites
Hello there,

Just pass a pointer to it ie

procedure Process2DArray(p2DArray: Pointer);
var
aArray: array of array of integer;
begin
aArray := p2DArray;

//do array stuff here
end;

then to call just use

procedure TestArray;
var
aArray: array of array of integer;
begin
Process2DArray(aArray);
end;

Note that you dont pass the pointer to the array
as an array is already a pointer (dont use the @ symbol
before the array identifier eg Process2DArray(@aArray) as
this will not work ).

Hope it helps.

Mark

Share this post


Link to post
Share on other sites
Another solution:

type MyArray = Array of Array of Integer;

function MyFunction(Arry: MyArray);
begin
Arry[0, 0]:= -1;
end;


- Arcane Lifepower -

"Although the world would call me free
Each day the more her slave am I
For in her very way to be
There''s I don''''t know what, I don''t know why"

Share this post


Link to post
Share on other sites
MButchers: that only works when passing an array of array of integer to the procedure. Try it with array[1..10] of array[1..10] of integer , and you''ll get:

quote:
Origional quote by my compiler
Incompatable types: ''Array'' and ''Pointer''



The procedure that Xorcist wants needs to be able to work with ALL 2D arrays of integers, no matter how they were declaired.

~ There''s no substitute for failure ~

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Lifepower: we''ve ran into the same problem here. Now, any variables passed to the procedure MUST be array of array of integer , and nothing else:

quote:
Origional quote by my compiler
Incompatable types: ''Array'' and ''MyArray''



~ There''s no substitute for failure ~

Share this post


Link to post
Share on other sites
Would it be possible to use variants to solve this problem? I''ve never been big on using them, and thus don''t know a whole lot about how they work and what would be required, but it''s a thought.

P.S. Exactly how are multidimensional arrays structured in Delphi? Are they completely linear and contiguous in memory? I''m just wondering if I could just take in the initial address of the array as a pointer, the size of a single element, and the size of the array, and manually index myself through the memory... sure it would be more work for me, but at this point anything I can get to work I''ll take...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!