Hi,
Can I have or make helper for arrays? like making Count property so I can use it instead of Length ?
For example :
IntegerArray : array of integer; .... for i:= to IntegerArray.Count -1 do ....
Regards,
Ara

Mailing lists / lazarus / 2016-10
9 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
Can I have or make helper for arrays? like making Count property so I can use it instead of Length ?
For example :
IntegerArray : array of integer; .... for i:= to IntegerArray.Count -1 do ....
Regards,
Ara
I don't know the answer about helper function but I also dislike Length() for arrays.
I solve this dislike by using
for i := Low(IntegerArray) to High(IntegerArray) dowhich covers more possibilities because it handles lower index limit that is non-zero.
Low() and High() also work with static arrays so you can use it almost everywhere.
Doug C.
---- On Sun, 02 Oct 2016 08:39:51 -0400Aradeonas via Lazarus <> wrote ----
Hi,
Can I have or make helper for arrays? like making Count property so I can use it instead of Length ?
For example :
IntegerArray : array of integer;....
for i:= to IntegerArray.Count -1 do....
Regards,
Ara
-- http://www.fastmail.com - The professional email service
Can I have or make helper for arrays? like making Count property so I can use it instead…
2016-10-02 14:39 GMT+02:00 Aradeonas via Lazarus <
: Can I have or make helper for arrays? like making Count property so I can use it instead of Length ?
Try to use TDynArray dynamic array wrapper provided by mORMot framework.
http://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_48
mORMot available out of box: http://newpascal.org
Can I have or make helper for arrays? like making Count property so I can use it instead…
Aradeonas wroteCan I have or make helper for arrays? like making Count property so I can use it instead of Length ?
Yes, you can. FPC 3.0 supports it and Lazarus CodeTools support them as well.
Ondrej
2016-10-02 14:39 GMT+02:00 Aradeonas via Lazarus < Try to use TDynArray dynamic array…
Thanks DougC I used it before but as I said before I want such helpers.
Thanks Maciej as always, I used NewPascal and I liked it but I want to find out FPC is supporting it or not.
Regards,
Ara
Ondrej can you point me to a sample?
I know I can make helper for array of integer but I want some helpers for all type of arrays.
Regards,
Ara
Aradeonas wroteI know I can make helper for array of integer
This is what I thought you want to.
but I want some helpers for all type of arrays.
Hmmm :( I don't know either.
Maybe you can raise a discussion / feature request in the fpc-devel mailing list to include type helpers for generic arrays? :
program Project1;
{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
{$modeswitch typehelpers}
type
generic TGenericArray<T> = array of T;
TIntArray = specialize TGenericArray<Integer>;
generic TGenericArrayHelper<T> = type helper for TGenericArray<T>
public
end;
begin
end.If not added, you'll need to create a generic record wrapper:
program Project1;
{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
{$modeswitch typehelpers}
type
generic TGenericArray<T> = record
private
FArray: array of T;
public
function Count: Integer;
end;{ TGenericArray }
function TGenericArray.Count: Integer;
begin
Result := Length(FArray);
end;
begin
end.Ondrej
2016-10-02 16:20 GMT+02:00 Ondrej Pokorny via Lazarus <
: Maybe you can raise a discussion / feature request in the fpc-devel mailing list to include type helpers for generic arrays? :
This was discussed in Smart Pointers topic:
http://free-pascal-general.1045716.n5.nabble.com/Smart-Pointers-td5725159.html
This is what I thought you want to. Hmmm :( I don't know either. Maybe you can raise a…
Maybe you can raise a discussion / feature request in the fpc-devel mailing list to include type helpers for generic arrays?
So we can have this feature for array it self and should use it for generic arrays?
Regards,
Ara