Author Topic: Accessing collection objects in GetElementsByQuery  (Read 4489 times)

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Accessing collection objects in GetElementsByQuery
« on: April 08, 2008, 07:42:17 am »
I know Repository.GetElementsByQuery returns an EA.Collection - but what types of objects are returned and how can I access their properties?

I'm pretty rusty at programming and learning C#.  I can't for the life of me figure out how to inspect the returned collection to find the underlying object types returned.

The collection contains a count of 5 after the method call and objecttype = otCollection.  What I want to know is what type of objects are contained in the collection so I can cast and use them appropriately.

Thanks,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Accessing collection objects in GetElementsByQ
« Reply #1 on: April 08, 2008, 07:59:44 am »
I suspect without proof that it returns a collection of Element objects. With each item you can inspect the Type property to determine what you got.

David
No, you can't have it!

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Accessing collection objects in GetElementsByQ
« Reply #2 on: April 08, 2008, 09:15:13 am »
Hi David,

Thanks for your reply.  I tried casting one of the objects in the collection to an Element via adding a watch in Visual Studio during debuggin and Visual Studio barfed, ie:

result = rep.GetElementsByQuery("Simple", "<search term>");
(Element)(result.GetAt(0));

I'll try running in code incase it is a syntax issue with my casting or a runtime issue calling GetAt() within the watch window.

Cheers,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Accessing collection objects in GetElementsByQ
« Reply #3 on: April 08, 2008, 10:25:33 am »
Remember to call GetAt with a short integer parameter.
No, you can't have it!

thomas.kilian

  • Guest
Re: Accessing collection objects in GetElementsByQ
« Reply #4 on: April 08, 2008, 05:13:17 pm »
ObjectType returns the type of the object. Search the help.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Accessing collection objects in GetElementsByQ
« Reply #5 on: April 08, 2008, 08:19:52 pm »
And remember that the object type of a (say) use case is element rather than use case. You need to use the type property to break it down to the specific type.

I trip over this each time I've been away from these collections for a few months.

David
No, you can't have it!

arose

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Accessing collection objects in GetElementsByQ
« Reply #6 on: April 15, 2008, 10:02:41 am »
This works:
  Dim oQueryElements As EA.Collection
  Dim oElement As EA.Element
  Set oQueryElements = Repository.GetElementsByQuery("Simple", "whatever")
  For Each oElement In oQueryElements
    msgbox "oElement.Name = " & oElement.Name
  Next oElement