Complex Collections with Gupta COM

In the last blog post, I described how to pass complex parameters in Gupta COM functions. Another major problem is to pass arrays of complex data structures such as orders and their positions. So far I had two solutions with neither I was happy with. One of them was to serialize data in JSON format and passing the resulting string. The other to create a SafeArray for each element of the data structure and then wrap it in a variant to pass it to COM.


Guptas COM Class Wizard offers a third option: A COM object where its interface is marked as a collection (see check box).



Sample Project

The turn: With my example I would like to
  • build a rudimentary order class consisting of orderid, customer and date
  • and an arbitrarily long list of order items consisting of articles and price defined as a complex data structure
  • provide a list of order records from a service class


First a class called OrderDetailItem is defined with the COM-Wizard with the properties Article (String) and Price (Number) as described similarly in the blogpost complex parameter with Gupta COM.



Then create a second class called OrderDetailCollection and check the property „Collection“.


Next, one has to specify the data type of the collection. For our example that is the class OrderDetailItem created above.


If you look at the resulting program code you can see that the collection consists of an array of OrderDetailItems. The array is not directly addressable in COM. Instead one can access it through the COM functions Item(..), Add(..), and Remove(..). Also one can read the property „Count“.

Unfortunately the wizard generates code with a small but crucial mistake: the internal array m_aCollection [*] is of type IOrderDetailItem. As described in the last blog post for „Instance Variables“ one has to use the CoClass  (the one without the leading I). One has to fix that manually otherwise one gets error messages at run time. By the way with the Gupta IDE (version 3.1) one cannot simply remove the „I“. Instead one has to remove the entire line and rewrite it correctly: OrderDetailItem: m_aCollection [*]



The order record in the example has the properties Id (number), Customer (String), Date (Date/Time) and – tadaa – OrderDetails of type IOrderDetailCollection.


But even here the wizard makes a mistake: the instance variable must be of type OrderDetailCollection (CoClass). Instead the wizard creates an InterfaceVar what even causes a compile error. The data types in the return value and parameters (PropSet – and PropGet- functions) however are correct (IOderDetailCollection).



For this sample I want to pass a list of orders. So we generate a collection of type OrderItem. Again one has to fix the type of the variable m_aCollection [] to the CoClass (the one without the „I“).


Finally a service COM class is created with the function „GetOrderCollection“ which returns the OderCollection defined above. Usually, of course, the data comes from a database. However, for the sample project I wrote functions that assign random values to all properties.


As a consumer, I have created a WinForm application with the freely available Visual Studio 2012 Express Edition (desktop). The registered COM object is included as a reference. The application brings up a list of sample orders created by our COM object and depicts it in a TreeView control.



All of the projects described in the blog are included in file

  • The Gupta 3.1 project „ComComplexCollection“
  • The VisualStudio project „ComComplexCollectionConsumer“
  • An executable demo application (assuming Gupta 3.1 runtime).

Happy Coding


Über thomasuttendorfer
Ich bin Entwicklungsleiter bei der Softwarefirma [ frevel & fey ] in München. Wir entwickeln Business-Software für Verlage und verwenden dafür den Gupta Team-Developer sowie Visual Studio.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )


Verbinde mit %s

%d Bloggern gefällt das: