Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Javascript arrays
Wed, Feb 1 2012 7:17 PMPermanent Link

Robert Devine

Hi Tim

I'm trying various ways of accessing array properties in external JS
code. If I do the following in JS:

this.TestArray = function(){
        return [10, 20, 30];
    }
this.TestArray2 = [4, 5, 6, 7];

and in EWB:

TIntegerArray = array of integer;

  external TDAClient = class
  public
    function TestArray: TIntegerArray;
    property TestArray2: TIntegerArray read;
  end;

1. TestArray: I can get the length of the array from the EWB code, but
if I access any of the members then I get a NaN.

2. TestArray2: If I try and read this property then the EWB code won't
compile ("the referenced variable,... TestArray2 does not exist).

Any ideas?

Thanks again, Bob
Wed, Feb 1 2012 7:54 PMPermanent Link

Robert Devine

I think I'm part of the way there. I used:

external TIntegerList = class
  public
    property items[index: Integer]: integer read; default;
    property length: Integer read;
  end;

property TestArray2: TIntegerList read;

I can get the values with this. Investigating other types now...

Cheers, Bob




On 02/02/2012 00:17, Bob Devine wrote:
> Hi Tim
>
> I'm trying various ways of accessing array properties in external JS
> code. If I do the following in JS:
>
> this.TestArray = function(){
> return [10, 20, 30];
> }
> this.TestArray2 = [4, 5, 6, 7];
>
> and in EWB:
>
> TIntegerArray = array of integer;
>
> external TDAClient = class
> public
> function TestArray: TIntegerArray;
> property TestArray2: TIntegerArray read;
> end;
>
> 1. TestArray: I can get the length of the array from the EWB code, but
> if I access any of the members then I get a NaN.
>
> 2. TestArray2: If I try and read this property then the EWB code won't
> compile ("the referenced variable,... TestArray2 does not exist).
>
> Any ideas?
>
> Thanks again, Bob
Fri, Feb 3 2012 8:07 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Bob,

<< I think I'm part of the way there. I used:

external TIntegerList = class
  public
    property items[index: Integer]: integer read; default;
    property length: Integer read;
  end;

property TestArray2: TIntegerList read;

I can get the values with this. Investigating other types now... >>

That is exactly correct.  Any psuedo-object in JS that acts like an array,
but has properties also, should be treated like an object whose default
property is an array property.  That's how I handle all of the DOM arrays
for node lists, etc.

--
Tim Young
Elevate Software
www.elevatesoft.com
Image