• Welcome to Theos PowerBasic Museum 2017.

'Items' again

Started by Edwin Knoppert, July 17, 2009, 09:50:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Edwin Knoppert

I have this simple interface for enumming menu items.
I keep struggling with the Items vs item members.

In .NET there is MenuItemCollection (mic) and a MenuItem (mi).
The mic has a 'this' member, this[0] is the first item.

Similar to the MI i do have a menuitem, in .NET it has a childitems member to obtain a mic.
I do the same but call it Items, should i implement the item by index part in the Items interface or directly in the menu interface?

In PB i suspect it would become like:
oItem = oMenuItem.Items.Item(0)

In .Net:
oItem = oMenuItem.ChildItems.this[0]

This looks the same but currently i have it like:
oItem = oMenuItem.Item(0)

What should i do?
I prefer to use the c# syntax and simply move this member.

Any suggestions for this?
Will i get into trouble with other future implementations where users may expect a similar notation like oItem = oMenuItem.Item(0)

Note that PB's Items member can not be used as in c# like: oItem = oMenuItem.ChildItems[0]
(We know that and it is a difference)


Edwin Knoppert

I just rewrote it to: oItem = oMenuItem.Items.Item(0)

And i guess it is the best thing to do..
It's logical items are in the Items collection/interface.

isn't?

José Roca

The usual is to have a property or method in the interface that returns a reference to the collection, and the collection implements at a minimum the Item, Count and _NewEnum properties (to work with For... Each).

Edwin Knoppert

Thank you, i thought so but i found it to 'nested'.
But i did the modification as i shown above, thanks for your input.
In the future i'll try me to implement the foreach stuff in some of my objects.

I you ever have an example?
(You confused me here, i thought it required an interface with the IEnumerator class id but now you mention the _NewEnum property so i have to check this out... TODO :) )

José Roca

 
_NewEnum must return a pointer to a custom implementation of the IEnumVARIANT interface. I don't have any example, sorry, but I have said several times that the Dictionary object can be used to implement collections.


' ########################################################################################
' Interface name = IDictionary
' IID = {42C642C1-97E1-11CF-978F-00A02463E06F}
' Attributes = 4176 [&H1050] [Hidden] [Dual] [Dispatchable]
' Inherited interface = IDispatch
' ########################################################################################

#IF NOT %DEF(%IDictionary_INTERFACE_DEFINED)
    %IDictionary_INTERFACE_DEFINED = 1

INTERFACE IDictionary $IID_IDictionary

   INHERIT IDispatch

   ' =====================================================================================
   PROPERTY SET putref_Item <0> ( _                     ' VTable offset = 28
     BYREF IN Key AS VARIANT _                          ' __in VARIANT* Key
   , BYREF IN pRetItem AS VARIANT _                     ' __in VARIANT* pRetItem
   )                                                    ' void
   ' =====================================================================================
   PROPERTY SET Item <0> ( _                            ' VTable offset = 32
     BYREF IN Key AS VARIANT _                          ' __in VARIANT* Key
   , BYREF IN pRetItem AS VARIANT _                     ' __in VARIANT* pRetItem
   )                                                    ' void
   ' =====================================================================================
   PROPERTY GET Item <0> ( _                            ' VTable offset = 36
     BYREF IN Key AS VARIANT _                          ' __in VARIANT* Key
   ) AS VARIANT                                         ' __retval_out VARIANT* pRetItem
   ' =====================================================================================
   METHOD Add <1> ( _                                   ' VTable offset = 40
     BYREF Key AS VARIANT _                             ' __in VARIANT* Key
   , BYREF Item AS VARIANT _                            ' __in VARIANT* Item
   )                                                    ' void
   ' =====================================================================================
   PROPERTY GET Count <2> ( _                           ' VTable offset = 44
   ) AS LONG                                            ' __retval_out long* pCount
   ' =====================================================================================
   METHOD Exists <3> ( _                                ' VTable offset = 48
     BYREF Key AS VARIANT _                             ' __in VARIANT* Key
   ) AS INTEGER                                         ' __retval_out VARIANT* pExists
   ' =====================================================================================
   METHOD Items <4> ( _                                 ' VTable offset = 52
   ) AS VARIANT                                         ' __retval_out VARIANT* pItemsArray
   ' =====================================================================================
   PROPERTY SET Key <5> ( _                             ' VTable offset = 56
     BYREF IN Key AS VARIANT _                          ' __in VARIANT *Key
   , BYREF IN rhs AS VARIANT _                          ' __in VT_VARIANT *rhs
   )                                                    ' void
   ' =====================================================================================
   METHOD Keys <6> ( _                                  ' VTable offset = 60
   ) AS VARIANT                                         ' __retval_out VT_VARIANT* pKeysArray
   ' =====================================================================================
   METHOD Remove <7> ( _                                ' VTable offset = 64
     BYREF Key AS VARIANT _                             ' __in VT_VARIANT* Key
   )                                                    ' void
   ' =====================================================================================
   METHOD RemoveAll <8> ( _                             ' VTable offset = 68
   )                                                    ' void
   ' =====================================================================================
   PROPERTY SET CompareMode <9> ( _                     ' VTable offset = 72
     BYVAL pcomp AS LONG _                              ' __in CompareMethod pcomp
   )                                                    ' void
   ' =====================================================================================
   PROPERTY GET CompareMode <9> ( _                     ' VTable offset = 76
   ) AS LONG                                            ' __retval_out CompareMethod* pcomp
   ' =====================================================================================
   METHOD NewEnum_ <-4> ( _                             ' VTable offset = 80
   ) AS IUnknown                                        ' __retval_out IUnknown** ppunk
   ' =====================================================================================
   PROPERTY GET HashVal <10> ( _                        ' VTable offset = 84
     BYREF IN Key AS VARIANT _                          ' __in VARIANT* Key
   ) AS VARIANT                                         ' __retval_out VARIANT* HashVal
   ' =====================================================================================

END INTERFACE

#ENDIF   ' /* __IDictionary_INTERFACE_DEFINED__ */


Edwin Knoppert

>_NewEnum must return a pointer to a custom implementation of the IEnumVARIANT interface.
Yes, should be simple.

>I have said several times that the Dictionary object can be used to implement collections
Yes, i need to do it once.

It is declared as IDispatch, isn't that a limitation?

José Roca

Quote
It is declared as IDispatch, isn't that a limitation?

No. It needs to be IDispatch to work with automation languages.