Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Dave_Bullet on April 08, 2008, 07:42:17 am

Title: Accessing collection objects in GetElementsByQuery
Post by: Dave_Bullet 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.
Title: Re: Accessing collection objects in GetElementsByQ
Post by: «Midnight» 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
Title: Re: Accessing collection objects in GetElementsByQ
Post by: Dave_Bullet 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.
Title: Re: Accessing collection objects in GetElementsByQ
Post by: «Midnight» on April 08, 2008, 10:25:33 am
Remember to call GetAt with a short integer parameter.
Title: Re: Accessing collection objects in GetElementsByQ
Post by: thomas.kilian on April 08, 2008, 05:13:17 pm
ObjectType returns the type of the object. Search the help.
Title: Re: Accessing collection objects in GetElementsByQ
Post by: «Midnight» 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
Title: Re: Accessing collection objects in GetElementsByQ
Post by: arose 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