Hi I am trying to develop my first couple of C++ XPCOM components for a
firefox extension I am working on.  There are 2 components that I am dealing
with one is LpWebService and the other is LpCategory.  If I create an
LpCategory object explicitly in javascript it behaves fine.  If I call the
GetCategories function on the LPWebService component It returns the correct
number of LPCategory objects but when I try to access an attribute the
script stops processing.  See the code below. Hopefully one of you XPCOM
gurus can help me. Thanks so much.


/** Javascript **/

   try{

//creating an LpCategory this way works and the second alert here  displays
the correct value.
     cat =
Components.classes["@interface.com/XPCOM/LpCategory;1"].createInstance(Components.interfaces.ILPCategory);
     alert(cat);
     cat.categoryId = 5;
     alert(cat.categoryId);

//Creating the webservice works this way as well
         obj =
Components.classes["@interface.com/XPCOM/LpWebService;1"].createInstance(Components.interfaces.ILPWebService);


var count = new Object();

     //GetCategories returns an array that has the correct number of
Categories
     var res = obj.GetCategories(true, count);
     alert(count);
     alert(res);
     alert(res.length);
     alert(res[0]);

     //everythign up until here works.  When I access the attribute of the
category object returned here it simply doesn't proceed past this point.
     alert(res[0].categoryId);
     }catch(e){
     alert(e);
   }



/*** C++  ***/

/* void GetCategories (in boolean refresh, out PRUint32 count, [array,
size_is (count), retval] out ILPCategory categories); */
NS_IMETHODIMP LPWebService::GetCategories(PRBool refresh, PRUint32 *count,
ILPCategory ***categories)
{
    // Initialize
    const int NR_TO_ALLOCATE = 1;
    *count = 0;

    // Allocate a one-member array of category pointers
    LPCategory **outArray = new LPCategory* [NR_TO_ALLOCATE];

    // Initialize the first and only member of the array to point to a newly
allocated category object
    outArray[0] = new LPCategory;

    // Set the returned number allocated
    *categories = (ILPCategory**)outArray;
    *count = NR_TO_ALLOCATE;
;

   return NS_OK;
}



/*** IDL ***/
#include "nsISupports.idl"

[scriptable, uuid(43e27230-97f0-11da-a72b-0800200c9a66)]
interface ILPCategory : nsISupports
{
 attribute long categoryId;
 attribute string categoryName;
};

[scriptable, uuid(86d8dce1-972e-11da-956d-00e08161165f)]
interface ILPWebService : nsISupports
{
 void GetCategories(in boolean refresh, out PRUint32 count, [array,
size_is(count), retval] out ILPCategory categories);
};
--
View this message in context: 
http://www.nabble.com/XPCOM-Oddities-t1093670.html#a2853856
Sent from the Mozilla - XPCOM forum at Nabble.com.

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to