[Pas2js] Initialize dynamic array feature

Michael Van Canneyt michael at freepascal.org
Thu Feb 15 22:07:02 CET 2018



On Thu, 15 Feb 2018, warleyalex via Pas2js wrote:

> It would be nice if we could do something like this, but we can not.
> -------------------------------------------------------------------
> var
>  dynamicArray  : array of String;
>  dynamicArray1 : array of String = ('one', 'two', 'three');
>
> begin
>   dynamicArray := ('one', 'two', 'three');  // we can not do this!
> end;
> -------------------------------------------------------------------

In time, we'll implement the Delphi syntax for this, for compatibility reasons:

type
    TMyFlexibleArray = array of Integer;

begin
   MyFlexibleArray := TMyFlexibleArray.Create(1, 2, 3 {...});
end;

procedure MyProc;

var
   A: array of Integer;
begin
   A := [1, 2, 3];
end;

> Another thing: #about TJSArray is when we declare, e.g.
>
> var
>  dynamicArray2: TJSArray;
>
> the pas2js compiler initialize the empty array with nil 
> this.dynamicArray2 = null;
>
> It would be handy if would initialize with [] instead of nil
> this.dynamicArray2 = [];

No, Pascal states that variables are not initialized.

That means either null or undefined.

Michael.


More information about the Pas2js mailing list