[Pas2js] array using enums
Mattias Gaertner
nc-gaertnma at netcologne.de
Wed Feb 14 23:53:57 CET 2018
On Wed, 14 Feb 2018 11:01:21 -0600 (CST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:
> Can you confirm: Array using Enums is not supported yet.
>
> //------------
> type
> TCars = (Ford, Vauxhall, GM, Nissan, Toyota, Honda);
>
> var
> cars : array[TCars] of string; // Range is 0..5
> //japCars : array[Nissan..Honda] of string; // Range is 3..5 --> not
> allowed in pas2js
Anonymous range as array range was not yet supported. It is now in
trunk.
Note that named enum range worked:
type
TjapCars: Nissan..Honda;
var
japCarsNames : array[TjapCars] of string;
I don't understand the below code, since there are two japCars. Is
there a bug?
> // We must use the appropriate enumeration value to index our arrays:
> japCars[Ord(TCars.Nissan)] := 'Bluebird'; // Allowed
> japCars[Nissan] := 'Bluebird'; // Allowed // not allowed
>
> japCars[Ord(TCars.Toyota)] := 'Galaxy'; // Allowed in pas2js
> japCars[Toyota] := 'Galaxy'; // not allowed in pas2js
>
> japCars[4] := 'Corolla'; // allowed in pas2js
> // japCars[4] := 'Corolla'; // Not allowed in delphi
>
> japCars[Ord(TCars.Ford)] := 'Galaxy'; // allowed in pas2js
> japCars[Ford] := 'Galaxy'; // Not allowed in delphi
>
> WriteLn(japCars[Nissan]); // not alowed in pas2js
> WriteLn(japCars[Toyota]); // not alowed in pas2js
>
> WriteLn(japCars[3]); // allowed in pas2js
> WriteLn(japCars[4]); // allowed in pas2js
>
> WriteLn(japCars[Ord(TCars.Nissan)]); // allowed in pas2js
> WriteLn(japCars[Ord(TCars.Toyota)]); // allowed in pas2js
Mattias
More information about the Pas2js
mailing list