SRL Archive - OSR Help

Counting ATPA entries


Bobzilla69

2010-03-28 10:37:23

Hey,

i want to count how many entries are in my ATPA, is this possible and how would i go about doing this?

thanks for any help

i luffs yeww

2010-03-28 10:48:18

Writeln(High(ATPA));

Bionicle

2010-03-28 10:50:16

High(x); works for ATPAs. It returns an integer for the highest part of the array.

Var
ATPA: T2DPointArray;
TPA, TPA2: TPointArray;
TP1, TP2, TP3, TP4: TPoint;
I: Integer;

Begin
TPA := [TP1, TP2];
TPA2 := [TP3, TP4];
ATPA := [TPA, TPA2];
I := High(ATPA) + 1;
Writeln(I);
End.

This returns as '2' in the debug box, the + 1 is there because it starts at 0.

E: :ninja:'d. Silly detailed responses :(

Bobzilla69

2010-03-28 11:05:22

From: i luffs yeww
Writeln(High(ATPA));


thanks for that

From: bionicle1800
High(x); works for ATPAs. It returns an integer for the highest part of the array.

Var
ATPA: T2DPointArray;
TPA, TPA2: TPointArray;
TP1, TP2, TP3, TP4: TPoint;
I: Integer;

Begin
TPA := [TP1, TP2];
TPA2 := [TP3, TP4];
ATPA := [TPA, TPA2];
I := High(ATPA) + 1;
Writeln(I);
End.

This returns as '2' in the debug box, the + 1 is there because it starts at 0.

E: :ninja:'d. Silly detailed responses :(


cheers for the detailed one, its better to give detailed answers it better understood then :P

Wanted

2010-03-28 15:24:22

The actual amount is WriteLn(Length(ATPA))

High is just the largest index.

i luffs yeww

2010-03-28 15:52:45

Isn't that the same thing?

Wanted

2010-03-28 15:59:17

From: i luffs yeww
Isn't that the same thing?


No they can be quite different.

var
S: array [5..10] of string;
I: Integer;


begin
S[5] := 'see';
S[6] := 'what';
S[7] := 'I';
S[8] := 'mean';
S[9] := '=P';
S[10] := '?';
WriteLn(IntToStr(Length(S)) + ' values');
WriteLn(IntToStr(High(S)) + ' high');
WriteLn(IntToStr(Low(S)) + ' low');
for I := Low(S) to High(S) do
begin
WriteLn('Index: ' + IntToStr(I));
WriteLn('Value ' + S[I]);
end;
end.

Successfully compiled (80 ms)
6 values
10 high
5 low
Index: 5
Value see
Index: 6
Value what
Index: 7
Value I
Index: 8
Value mean
Index: 9
Value =P
Index: 10
Value ?
Successfully executed

i luffs yeww

2010-03-28 17:54:20

Well in most cases it'd start at 0. :p

Wanted

2010-03-28 18:29:17

From: i luffs yeww
Well in most cases it'd start at 0. :p


If you start at 0 then he would need to add one. It's simpler/more accurate to use Length.