[Pas2js] High

warleyalex warleyalex at yahoo.com.br
Tue Jun 25 00:56:27 CEST 2019


It seems there is an issue with High 

======== 
var 
  fruits : array of String = ('Banana', 'Orange', 'Apple', 'Mango', 
'Banana', 'Abacate', 'Apple'); 
begin 
  TJSArray(fruits).push('kiwi'); 
  for Index := Low(fruits) to High(fruits) do 
     console.log( fruits[Index] ); 
end; 
======== 

JS output 
//------------- 
$mod.fruits.push("kiwi"); 
for ($mod.Index = 0; $mod.Index <= 6; $mod.Index++) 
window.console.log($mod.fruits[$mod.Index]); 

console output: 
------------------ 
Banana 
Orange 
Apple 
Mango 
Banana 
Abacate 
Apple 

//---the correct should be------------------------- 
$mod.fruits.push("kiwi"); 
for ($mod.Index = 0; $mod.Index < $mod.fruits.length; $mod.Index++) 
window.console.log($mod.fruits[$mod.Index]); 

Banana 
Orange 
Apple 
Mango 
Banana 
Abacate 
Apple 
kiwi 

ahn, if we change High to Length, it works as expected.

  TJSArray(fruits).push('kiwi'); 
  for Index := Low(fruits) to Length(fruits) do 
     console.log( fruits[Index] ); 

it translates corretly
$mod.fruits.push("kiwi");
    for ($mod.Index = 0; $mod.Index <= 7; $mod.Index++)
window.console.log($mod.fruits[$mod.Index]);

---------
Banana 
Orange 
Apple 
Mango 
Banana 
Abacate 
Apple 
kiwi 



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


More information about the Pas2js mailing list