As I worked on next version of Boogie I encountered a really big problem with returning of an array of instances of my components returned from another component’s method.
Here is the introduction: I have component odIBoogieDatatypeProject and also component odIBoogieDbService where is method getProjects(aWhere) which should returns array of all projects which matching given WHERE part of SQL query. The returned array should contains instances of odIBoogieDatatypeProject.
The final solution (I’m omitting implementation of odIBoogieDatatypeProject component here becouse is not needed) – the important parts are highlighted by yellow background:
Implementation in odIBoogieDbService.idl:
/**
* Returns projects which match given pattern.
*
* aWhere WHERE part of the SQL query.
*/
void selectProjects(in AString aWhere,
out unsigned long aCount,
[array, size_is(aCount), retval] out odIBoogieDatatypeProject aRetVal);
Implementation in odIBoogieDbService.js:
/**
* Returns projects which match given pattern.
*
* @param aWhere {string} WHERE part of the SQL query.
* @param aCount {object}
* @returns {array} Returns array of instances of odIBoogieDatatypePerson.
* @throws Exception Throws exception whenever the SQL query failed.
*/
selectProjects: function(aWhere, aCount, aRetVal)
{
let ret = new Array();
// ... I'm creating a array 'ret' here with projects to return...
aCount.value = ret.length;
return ret;
}, // end selectPersons(aWhere, aCount, aRetVal)
And here is how I’m using it in target JavaScript:
let db = Components.classes["@ondrejd.info/boogie/db-service;1"]. getService(Components.interfaces.nsIBoogieDbService); let projects = db.selectProjects("", {}); for(let i=0; i let project = projects[i]; // ... } // ...
The best documentation which shows me the right way I found on page FAQ on XPConnect and XPIDL
