SRL Archive - Help and Support

Multidimensional Array in Function


Sir R. M8gic1an

2007-12-17 15:13:23

ok so here's what i tried to do:


function DoTheStuff(bebe:array[0..7] of array of integer): boolean;
begin
{...}
Result := True;
end;

procedure ThisProc;
begin
DoTheStuff( {<---- Line 38}
[
[1, 2, 3, 4], {...}
[5,6], [7,8], [9,10], [11,12], {...}
[13], [14], {...}
[15,16,17,18,19,20,21,22] {...}
]
);
end;

begin
ClearDebug;
ThisProc;
end.

and this is the error i got:
[Runtime Error] : Could not call proc in line 38 in script

it really doesn't give me much of a clue and i tried playing around with it… but i really don't know whats wrong :s help, anyone?

Thanks in Advance
~RM

Markus

2007-12-17 15:17:49

I dont think scar supports declaring multidimensional arrays all at once…

Sir R. M8gic1an

2007-12-17 15:22:31

From: Markus
I dont think scar supports declaring multidimensional arrays all at once…


thx, i guess that would explain it…. i'll get working on a fix for it.

i wonder if anyone else knows something about this?

~RM

Wizzup?

2007-12-17 15:29:09

bebe?
Anyway SCAR supports multideminsional arrays, but you have to declare them differently, eg: array[0][5] := 7474;

Sir R. M8gic1an

2007-12-17 15:50:50

kk, thank you :) and i just found out i can do
array1 := array2; and it'll actually take all the values in the same order without any problems at all:)

~RM

Wizzup?

2007-12-17 16:56:43

From: Rasta Magician
kk, thank you :) and i just found out i can do
array1 := array2; and it'll actually take all the values in the same order without any problems at all:)

~RM


Sooner or later there will be problems. Delphi and SCAR have pointer problems.
Just set each value of the array. EG:
Setlength(array2, length(array1);
l:=high(array1);
for i:=0 to l do
array2[i] := array1[i];
That way is safe, it gives no pointer errors.
It took me (and raymond) a few days to find that out.

R0b0t1

2007-12-17 17:24:27

What are you talking about? I can set Multi-Arrays like that? :confused:


I think you can't just declare one dimension, though.

{If you insist on not declaring at once...}
procedure SetMultiLength(ArrayToSet: T2DIntArray; SetLength: TIntegerArray);
var
I, B: Integer;
begin
B:= GetArrayLength(ArrayToSet) - 1;
for I:= 0 to B do
SetArrayLength(ArrayToSet[I], SetLength[I]);
end;

mastaraymond

2007-12-17 17:33:44

From: R0b0t1
What are you talking about? I can set Multi-Arrays like that? :confused:


I think you can't just declare one dimension, though.


Yes, you can set them like that.. But its a nasty 'bug'..

Here run this, you will see the problem

program New;
var
Ints, Ints2 : TIntegerArray;
I : integer;
begin
SetLEngth(Ints,6);
For I := 0 to 5 do
Ints[I] := I;
Ints2 := Ints;
For I := 0 to 5 do
Ints2[I] := I + 99;
For I := 0 to 5 do
Writeln(inttostr(ints[I]));
end.

Notice, we set the value's of Ints to 0..5, the values of Ints2 to 99..104.. But we did Ints2 := Ints; So the values of Ints will change to :eek:

R0b0t1

2007-12-17 18:22:26

Interesting… So if I set the secondary dimension smaller, I can make it larger by just doing:


Array[I]:= [1, 2, 3, 4, 5];

Negaal

2007-12-18 13:22:53

[Runtime Error] : Could not call proc


I got same error for doing
For I to GetArrayLength(blabla) Do

I can fix it same way as mentioned above?

mastaraymond

2007-12-18 15:19:04

From: R0b0t1
Interesting… So if I set the secondary dimension smaller, I can make it larger by just doing:


Its not a 'bug'. Its because, i guess, TPA is only a Pointer to the whole array, with some Length iformation.. So if you change the pointer, it will edit the other one.. Kinda makes sense.

Sir R. M8gic1an

2007-12-19 15:15:56

From: Negaal
I got same error for doing
For I to GetArrayLength(blabla) Do

I can fix it same way as mentioned above?


i don't think the problem would be with the for to do, i think it'd be with procedure you call in it?

~RM

The Claw

2007-12-19 19:23:13

From: Negaal
I got same error for doing
For I to GetArrayLength(blabla) Do

I can fix it same way as mentioned above?


Try putting a -1 at the end, or doing For I to High(blabla)

Santa_Clause

2007-12-19 19:35:45

From: The Claw
Try putting a -1 at the end, or doing For I to High(blabla)


I was thinking he'd get more of an Out Of Range error…