Hi,
I have one Pages collection class, in which i have defined inexer.
My collection class is COM enabled, and i am using its object in my
scripting engine.
Now, when i using Jscript in my scripting engine, i think the C#
objects indexer is not supported in JScript.
I can't make access as follows in JScript:
Pages[0].PageID = 100;
Any help will be appreciated....
Thanx in advance.
Regards,
SUNIL RUPAVATIYA
Oleg Sych - 01 Sep 2006 21:54 GMT
JScript supports indexers with () instead of []. You should be able to access
your collection using the following syntax:
Pages(0).PageID = 100;
There is one pitfall though. This syntax will only work if Pages is a
variable and not a property of another object. So this code works:
var pages = new ActiveXControl("MyNamespace.MyDotNetCollection");
pages.Add(newPage);
pages(0).PageID = 100;
but this code, where collection is returned by a property of another .NET
object, will report a "Wrong number of arguments or invalid property
assignment" error:
var myObject = new ActiveXControl("MyNamespace.MyDotNetObject");
myObject.Pages(0).PageID = 100;
You would have to use the following syntax as a workaround:
myObject.Pages.Item(0).PageID = 100;
// or
var pages = myObject.Pages;
pages(0).PageID = 100;
Does anyone know why object.Collection(x) syntax doesn't work in JScript and
VBScript with .NET collections? Having to resort to object.Collection.Item(x)
syntax is a significant usability problem for an object hierarchy with
multiple levels of objects nested in collections. Compare
company.Customers("Smith, John").Orders("555").Items(0)
// and
company.Customers.Item("Smith, John").Orders.Item("555").Items.Item(0)
I tried to use both AutoDispatch, explicit IList and explicit custom class
interfaces with my collections. I can only get indexers to work using
collectionVariable(index) syntax but not with
object.CollectionProperty(index). There are differences in the IDL generated
for my .NET collections and classic collections, such as
IHTMLElementCollection in mshtml.tlb, where I know the right syntax works.
There must be something in the .NET/COM interop that makes them different and
prevents .NET collections from working correctly.
Any help would be very appreciated.
Thanks,
Oleg
> Hi,
>
[quoted text clipped - 15 lines]
> Regards,
> SUNIL RUPAVATIYA