[fpc-pascal] Feature announcement: Dynamic array extensions

Sven Barth pascaldragon at googlemail.com
Thu May 24 20:37:43 CEST 2018


Am 24.05.2018 um 17:27 schrieb Ryan Joseph:
>
>> On May 20, 2018, at 7:23 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> The compiler now implements a "+" operator for arrays which is the same as if Concat() would be called on the arrays.
>>
> I haven’t built it yet but I’m curious, does += now push an element to the array or does this just work to concat 2 arrays? I would expect:
>
> a: array of string = ();
> a += ‘foo’;
>
>
> to push a single string on the array.

This is currently not supported. And to avoid backwards compatibility 
problems with existing operator overloads you'd probably need to convert 
it to a dynamic array first:

=== code begin ===

a += ['foo'];

=== code end ===

> Also can you use type helpers with dynamic arrays yet? Thinking about how to extend them if possible.

Type helpers for dynamic arrays are already possible in 3.0, however 
they must be named array types (both for the declaration of the helper 
as well as the array) and they must be the same type (so equal type 
declarations in different units do not work).

=== code begin ===

{$modeswitch typehelpers}

type
   TLongIntArray = array of LongInt;

   TLongIntArrayHelper = type helper for TLongIntArray
     procedure Test;
   end;

procedure TLongIntArrayHelper.Test;
begin
   Writeln(Length(Self));
end;

var
   lia: TLongIntArray = (1, 2, 3);
begin
   lia.Test;
end.

=== code end ===

Regards,
Sven



More information about the fpc-pascal mailing list