PDA

View Full Version : function GetLength- similar to Length and GetArrayLength



Cazax
03-16-2008, 06:05 PM
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
03-16-2008, 06:10 PM
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
03-16-2008, 06:23 PM
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
03-16-2008, 06:28 PM
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
03-16-2008, 06:33 PM
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
03-16-2008, 06:42 PM
No they aren't if you don't get them ;)

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

Cazax
03-16-2008, 06:49 PM
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:
http://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Choco_chip_cookie.jpg/1000px-Choco_chip_cookie.jpg

Negaal
03-16-2008, 06:57 PM
Length(arr) would do, sorry but your's is pointless. :S

Cazax
03-16-2008, 06:59 PM
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
03-17-2008, 12:02 AM
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
03-17-2008, 12:09 AM
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?
03-17-2008, 12:13 AM
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
03-17-2008, 01:27 AM
Also, Length = High + Low + 1.

Length = High - Low + 1 ;)

Negaal
03-17-2008, 05:46 AM
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
03-17-2008, 07:19 PM
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!

-


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.