Re:Find objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re:Find objects

David A Smith
Darn it - did not see this one either.

#find: does indeed return a collection - even possibly an empty collection if it doesn't actually find anything. You can find the size of a collection with #size.

So you can try:

   collection := tgroup find:'xyzzy'.
   collection size>1 ifTrue:[^ collection first.].
 
   or: collection at: 1

The reason it returns a collection is there may be more than one object with the same name. If you need a unique identifier, use the objectID, which is an instance of TObjectID.