Objects (using)

eSignal EFS

Objects (using)

 

The "Object" type can be used in EFS to emulate the "struct" and "record" types in C and Delphi respectively. Arrays of objects can be created as well. It can also be used in conjunction with user defined functions to return more than one value.

 

Creating Objects

 

var myObj = new Object;

 

myObj.priceHigh = high();

myObj.priceLow = low();

myObj.percentChange = (close()-close(-1))/close(-1);

 

You can also create a new object using a function:

 

function PriceData( high, low, pChange ) {

this.priceHigh = high;

this.priceLow = low;

this.percentChange = pChange;

}

 

You would call this function from within your code as follows:

 

var myObj = new PriceData( high(), low(), (close()-close(-1))/close(-1) );

 

You can access the information in your object as follows:

 

with (myObj) {

debugPrint( priceHigh + " : " + priceLow + " : " + percentChange + "\n");

}

 

 

Arrays of Objects

 

Creating an array of objects is simply a matter of assigning an Object to an array element:

 

var myArray = new Array();

 

for (x=0; x<20; x++) {

//create the object

var tmp = new Object;

//fill the object with data

tmp.priceHigh = high(-x);

tmp.priceLow = low(-x);

tmp.priceChange = (close(-x)-close(-(x+1)))/close(-(x+1));

//assign it to the array element

myArray[x] = tmp;

}

 

To access the data in your array of objects, you could do the following:

 

for (x=0; x<20; x++) {

with (myArray[x]) {

  debugPrint( priceHigh + " : " + priceLow + " : " + percentChange + "\n");

}

}

 

 

Passing Objects to Functions

 

Objects can be used to return multiple values from a function.

 

var tmp = new Object;

 

tmp.Hival = 0;

tmp.Loval = 0;

 

getHiLo( tmp );

 

...

...

 

 

function getHiLo( oAnObject ) {

oAnObject.Hival = high();

oAnObject.Loval = low();

return;

}

 

Arrays

Number Operations