SRL Archive - RS3 Help

Too many parameters


rj

2014-01-01 00:49:47

Very simple.


function tstringarray.length:integer;
begin
result := length(self);
end;


why am I getting a too many parameters error at line

result := length(self);


:S

riwu

2014-01-01 02:22:20

Looks like a bug to me.
A temporary bypass would be to do
result:= High(self) + 1;

Brandon

2014-01-01 03:14:46

From: riwu
Looks like a bug to me.
A temporary bypass would be to do
result:= High(self) + 1;


It isn't a bug at all. He has length defined for the tstringarray and he's trying to call length but instead is calling self.length(self). He needs to call global scope length on self.

If his Function was defined as follows:


Function TStringArray.Length(param: TStringArray): Integer;
Begin
Result := Length(Self);
End;

He'd have a stackoverflow due to infinite recursion. In other words, length(self) is actually calling itself and not the Global Length function which he is overriding.


Only solution I know of is to do:


Function TStringArray._Length(param: TStringArray): Integer;
Begin
Result := Length(Self);
End;

I don't know myself how to call global Length..

Turpinator

2014-01-01 03:57:21

perhaps you could do…
Function TStringArray.len(): Integer;
Begin
Result := Length(Self);
End;
could even overload it to this…
procedure TStringArray.len(var l: Integer); overload;
begin
l := length(self);
end;

(second just auto stores the length into the param ie…
lootNames.len(lootlen); vs lootlen := lootNames.len();

rj

2014-01-01 12:03:41

Yea I figured I couldn't use length to I just used tstringarray.size

Brandon

2014-01-01 13:24:48

From: Officer Barbrady
Yea I figured I couldn't use length to I just used tstringarray.size


Can always use pointers and get the length from the array's -4 byte offset from index 0.. This will work for any array data-type.

Function TStringArray.Length: Integer;
type PInt = ^Integer;
Begin
Result := (PInt(@Self[0]) - sizeof(Integer))^ + 1;
End;

Function TStringArray.Length2: Integer;
type PInt = ^Integer;
Begin
Result := PInt(@Self[-1])^ + 1; //same as the above function. Just easier to understand?
End;

Function TStringArray.High: Integer;
type PInt = ^Integer;
Begin
Result := (PInt(@Self[0]) - sizeof(Integer))^;
End;

Function TStringArray.High2: Integer;
type PInt = ^Integer;
Begin
Result := PInt(@Self[-1])^; //same as the above function. Just easier to understand?
End;

Think of it this way:


int Array[10];
int length = Array[-1]; //This only works in pascal. NOT in C!
int length = int(&Array[0] - 1); //same exact thing as above.

char Array[40];
int length = int(&Array[0] - 4); //4 bytes. This only works in pascal. NOT in C!


Not sure who wrote:
No idea what you said, i know its written in latin letters for the english language. That is all


Basically OP overloaded the length function and wasn't able to call the original function because his overload is being called instead. Not sure how to explain it easier..


Anyway, I've been using the above code in C & C++ for reading pascal array lengths.. Works just fine for Simba. Try it.

Dgby714

2014-01-01 13:55:26

Most of Lape's method can also be accessed under System.

function TIntegerArray.Length(): UInt32;
begin
Result := System.Length(Self);
end;