SRL Archive - OSR Help

TPA/TBox array help


Junior

2010-05-30 20:05:25

What procedures are used to add on to an array and to clear an array. I have multiple Tpoints as well as Tboxes that need to be stored in an array(I know you cant store TPAs and Tboxarrays together), and cleared in the same procedure. My mind has gone blank. I dont know much about TPAs and TBoxarrays and the search has led me to nothing. Thanks for your help guys.

nielskool

2010-05-31 07:11:00


program new;
var
Array : Array[0..3] of Integer;
NewArray : Array of Integer;
I: integer;

Begin
Array[0]:= 1;
Array[1]:= 5;
Array[2]:= 8;
For I:=0 to Length(Array)-1 do
Setlength(Newarray, I+1);
Newarray[I]:= array[I];
SetLength(Array, 0);// clear Array
end.

are the Tpa's within the Tboxes?
if so you could do this:

type
Newarrray = record;
Tbox : Tbox;
TPAs : TPointArray;
end;

Gu3st...

2010-05-31 07:15:06

To add something to an array, just make the array bigger (SetArrayLength(Array, GetArrayLength(Array)+1); ) and to clear one do SetArrayLength(Array, 0);

nielskool

2010-05-31 07:22:27

From: Zyt3x
To add something to an array, just make the array bigger (SetArrayLength(Array, GetArrayLength(Array)+1); ) and to clear one do SetArrayLength(Array, 0);


What is the diffrence between Length and GetArrayLenght?
I always use Length.

Gu3st...

2010-05-31 07:56:56

There is no difference (AFAIK).
I just do GetArrayLength() because it's good practice :)

Bad Boy JH

2010-05-31 09:27:23

Should I dare ask why its "good practice" to use GetArrayLength not just Length?

nielskool

2010-05-31 11:09:59

From: Zyt3x
There is no difference (AFAIK).
I just do GetArrayLength() because it's good practice :)


The diffrence i notice is that i can't do
Value := GetArrayLength(Array);
Writeln(inttostr(value));

But i can do:
Value := Length(Array);
Writeln(inttostr(value));

Gu3st...

2010-05-31 11:27:46

From: Bad Boy JH
Should I dare ask why its "good practice" to use GetArrayLength not just Length?
Because Length() should actually be for strings, while GetArrayLength should be for arrays :)
Actually, there should be a StrLen() imo (even though Length() is just fine)

EDIT:
From: nielskool
The diffrence i notice is that i can't do
Value := GetArrayLength(Array);
Writeln(inttostr(value));

But i can do:
Value := Length(Array);
Writeln(inttostr(value));


Both work just fine for me :P

nielskool

2010-05-31 12:00:25

GetArrayLength gives me:
[Runtime Error] : Could not call proc in line 6 in script
Simba and SCAR 3.22

Gu3st...

2010-05-31 12:10:12


nielskool

2010-05-31 12:57:31

i know what is the problem xD
it doesn't work if you do this:
arr: array[0..3] of integer;

and that is what i did to try it.. so normaly it would work.

i luffs yeww

2010-05-31 17:33:00

^ SCAR 3.22? We're on 3.23.

Junior

2010-05-31 23:29:18

Thanks for the GetArrayLength and SetLength, but thats just for integers right? how do i add a Tpoint into an array though?
Pt := Point(T[r].x, T[r].y);
Pts := SetArrayLength(Pt, GetArrayLength(Pts)+1); ?? I dont know what to do here.
Same thing goes for tboxes.

Gu3st...

2010-06-01 05:35:27

var
P : TPoint;
TPA : TPointArray;

begin
P := Point(1, 1);
TPA := [Point(0, 0), Point(0, 1), Point(1, 0)];
SetArrayLength(TPA, GetArrayLength(TPA)+1);
TPA[High(TPA)] := P;
end.

Junior

2010-06-03 15:04:48

Thanks a lot zyt3x!

Gu3st...

2010-06-03 15:12:40

From: Junior
Thanks a lot zyt3x!
No problem mate ^^