SRL Archive - Research & Development Lounge

function GetLength- similar to Length and GetArrayLength


Cazax

2008-03-16 14:05:49

function GetLength(arr: TpointArray): integer;
var
i, Length : integer;
begin
for i:=0 to High(arr) do
begin
Inc(Length);
end;
result := Length;
end;

you can change (arr: TPointArray) to another variable if you arent using TPointArray, e.g: (arr: T2DPointArray).

test it:

open SCAR, paste this and click start.
program New;
var
x,y : integer;
TPA : TPointArray;
function GetLength(arr:TpointArray): integer;
var
i, Length : integer;
begin
for i:=0 to High(arr) do
begin
Inc(Length);
end;
result := Length;
end;
begin
FindColorsTolerance(TPA, 16777215, 365, 528, 365, 529, 1);
Writeln(IntToStr(GetLength(TPA)))
Writeln(IntToStr(Length(TPA)))
end.
the results will be the same.

n3ss3s

2008-03-16 14:10:50

But why did you make a function like this?

There are Length and GetArrayLength which both are a lot faster than this :rolleyes:

Also, remember not to use a function name of SCAR (not SRL) as a global variable, since it overrides the function and can cause terrible things.

Cazax

2008-03-16 14:23:00

From: n3ss3s
But why did you make a function like this?

There are Length and GetArrayLength which both are a lot faster than this :rolleyes:

Also, remember not to use a function name of SCAR (not SRL) as a global variable, since it overrides the function and can cause terrible things.


becouse i was bored, i know that Length and GetArrayLength are faster, i was testing my abilities.

and the last thing, why can it cause terrible things?

n3ss3s

2008-03-16 14:28:32

Hasn't your mommy ever told you about…

A non-runtime error?

-Oh my god! What is that?!


Program New;

Var
Length, I: Integer;

begin
For I := 1 To Length('string') Do
Writeln('<0.o>');
end.

Cazax

2008-03-16 14:33:32

From: n3ss3s
Hasn't your mommy ever told you about…

A non-runtime error?

-Oh my god! What is that?!


Program New;

Var
Length, I: Integer;

begin
For I := 1 To Length('string') Do
Writeln('<0.o>');
end.


they arent terrible things, runtime errors are terrible.

n3ss3s

2008-03-16 14:42:19

No they aren't if you don't get them ;)

a) Script right
b) Use Try - Except ( - Final ) at dangerous areas.

Cazax

2008-03-16 14:49:32

From: n3ss3s
No they aren't if you don't get them ;)

a) Script right
b) Use Try - Except ( - Final ) at dangerous areas.


im ok now.

btw, im going to give you a cookie:

Negaal

2008-03-16 14:57:21

Length(arr) would do, sorry but your's is pointless. :S

Cazax

2008-03-16 14:59:10

From: Negaal
Length(arr) would do, sorry but your's is pointless. :S


yes, i tried that but it gave me this error:
[Error] (2:24): colon (':') expected in script

bullzeye95

2008-03-16 20:02:53

Then something was wrong, probably around that line… if you post it, I (or somebody else if they get here first) will fix it…

Cazax

2008-03-16 20:09:35

From: bullzeye95
Then something was wrong, probably around that line… if you post it, I (or somebody else if they get here first) will fix it…


function GetLength(x): integer;

thats the error

Wizzup?

2008-03-16 20:13:04

You should not overwrite the Length() function with a variable called length.
Like this:

program New;

var
point:tpoint;
begin
point:=point(x, y);
end.

Causes type mismatches.

Also, Length = High + Low + 1.

bullzeye95

2008-03-16 21:27:57

From: Wizzup?

Also, Length = High + Low + 1.


Length = High - Low + 1 ;)

Negaal

2008-03-17 01:46:32

From: Cazax
function GetLength(x): integer;

thats the error


It might be caused because of multi-dimensional array aswell, if you using that, then you have to say it's index aswell.

n3ss3s

2008-03-17 15:19:36

From: Wizzup?
You should not overwrite the Length() function with a variable called length.
Like this:

program New;

var
point:tpoint;
begin
point:=point(x, y);
end.

Causes type mismatches.

Also, Length = High + Low + 1.



Hey - you can't steal people's points like that!

-

From: n3ss3s
Hasn't your mommy ever told you about…

A non-runtime error?

-Oh my god! What is that?!


Program New;

Var
Length, I: Integer;

begin
For I := 1 To Length('string') Do
Writeln('<0.o>');
end.