Re: collections

Klaus Dicks <[email protected]>
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <[email protected]>
try this:

       List drives = new ArrayList();

       DispatchPtr fso = new DispatchPtr("Scripting.FileSystemObject");
       SafeArray sa = fso.get("Drives").toSafeArray;
       for(int i = sa.getLBound(); i <= sa.getUBound(); i++)
       {
          Object drive = sa.getVariant(i).toDispatch();
          drives.add(drive);
       }

       return (Object[]) drives.toArray(new Object[0]);


Heiko Selber wrote:
> I am trying to access the items of a collection, or to create a
> Enumeration for the collection, but don't seem to get anywhere.
>
> If I am wasting bandwidth with a stupid question, please simply point me
> to some stuff to read.
>
> In detail, I want to find out the properties of drives. I have managed to
> get this far with a lot of trial and error:
>
> DispatchPtr fso = new DispatchPtr("Scripting.FileSystemObject");
> DispatchPtr drives = (DispatchPtr) fso.get("Drives");
>
> According to http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/script56/html/jscoldrives.asp the next step would be to create an
> Enumeration over drives, but I cannot seem to do it.
>
> I tried to mimick some approaches the I found on this list to access
> individual members, but failed with various errors, e.g.:
>
> Object[] drives = (Object[]) drives.invokeN("Item",
>                         new Object[] { new Integer(i) });
>
> I am completely lost here, because I am not experienced with Windows
> scripting. The Jawin javadoc is not much help, either.
>
> I know that the collection has a property named Count that matches the
> expected number of items:
>
> Integer numDrives = (Integer) drives.get("Count");
>
> Thanks in advance,
>
> Heiko Selber
>
> PS: It seems that this question was already posted to the list over a year
> ago, but never answered:
>
>
>>Date:         Fri, 21 Nov 2003 11:30:43 -0500
>>From:         Ken Larson <[email protected]>
>>Subject:      collections
>
>
>>I am trying to deal with a com class that returns a collection from a
>>method.  I see there is some code in jawin to help deal with collections
>>and enumerations, but I am not sure how complete it is or how exactly to
>>use it.
>
>
>>Can anyone give me any pointers as to how I would access a collection
>>(and also logically, an enumeration) using jawin?
>
>
>>Thanks,
>
>
>>Ken Larson
>
>


--
freundliche Grüsse

Klaus Dicks
Organisationsprogrammierer

--
SHD Datentechnik GmbH, Bereich MHS, Rennweg 60, 56626 Andernach
Telefon (0 26 32) 2 95-685   Fax (0 26 32) 2 95-488
mailto:[email protected]   http://www.shd.de
--
If your program isn't worth documenting,
it probably isn't worth running
(Nagler)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.