[Pas2js] array using enums

warleyalex warleyalex at yahoo.com.br
Wed Feb 14 18:01:21 CET 2018


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
   japCars : array[Ord(TCars.Nissan)..Ord(TCars.Honda)] of string;  // Range
is 3..5

begin
// Note: The cars array is defined using just a data type - TCars. The size
and range of the data type dictates how we use the array.

// 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


  { CONSOLE OUTPUT
    Bluebird
    Galaxy
  }




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list