Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-10

Helper for arrays

9 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

DougC
to Aradeonas

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) do

which 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

Reply by email

Maciej Izak
to Aradeonas: 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

Best regards, Maciej Izak -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20161002/e344add5/attachment.html>

Reply by email

Aradeonas
to Maciej Izak: 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

http://www.fastmail.com - Send your email first class -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20161002/05e71b4f/attachment.html>

Reply by email

Ondrej Pokorny
to Aradeonas
Aradeonas wrote
I 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

Reply by email

Maciej Izak
to Ondrej Pokorny

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

Best regards, Maciej Izak -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20161002/84be4304/attachment.html>

Reply by email

Aradeonas
to Ondrej Pokorny: 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

http://www.fastmail.com - A no graphics, no pop-ups email service -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20161002/de9c5a35/attachment.html>

Reply by email