Passing a type to a method, C# versus Visual COBOL. How to code it.

DevExpress C# sample code:

  [Association]
public XPCollection<Order> Orders {
get { return GetCollection<Order>(nameof(Orders)); }
}

I'm trying to get back a collection of "Order" objects by

invoking the GetCollection method. The Visual COBOL editor shows this syntax for method:

XPBaseObject::GetCollection(propertyName AS string) RETURNING type DevExpress.Xpo.XPCollection[type T].

This is what I've coded so far:

property-id trans_items type XPCollection[type WN_160_UnitOfWork.trans_item] public
attribute Association.
getter.
set property-value to GetCollection("trans_items")
end property.

The editor tells me I can't convert type DevExpress.Xpo.XPCollection to what I've defined in the property-id statement.



  • DevExpress C# sample code:

    public XPCollection<Order> Orders {
    get { return GetCollection<Order>(nameof(Orders)); }
    }

    ...

    property-id trans_items type XPCollection[type WN_160_UnitOfWork.trans_item] public
    attribute Association.
    getter.
    set property-value to GetCollection("trans_items")
    end property.

    The editor tells me I can't convert type DevExpress.Xpo.XPCollection to what I've defined in the property-id statement.


    Off the top of my head, without trying something similar: Note that the C# code type-qualifies the invocation of GetCollection in the getter. You aren't doing that in your getter. So try:

    set property-value to GetCollection[type WN_160_UnitOfWork.trans_item]("trans_items")

  • Your suggestion should work but gives this error:

    COBCH1711 :'type WN_160_UnitOfWork.basic_trans' has no visible method 'GetCollection[type WN_160_UnitOfWork.trans_item]' with 1 parameter(s)

  • OK, I'll have to try to reproduce the problem and play around with it.

    What Visual COBOL / Enterprise Developer version are you running (including Patch Update level)?

  • We're using Visual COBOL 2.3., no patches.

    We are also using DevExpress for our user interface.

    I'm trying to call a DevExpress method which takes a generic collection as a parameter.

  • Ouch. That's ancient (well, four years old, which counts as ancient in these parts). And no longer supported.

    I would strongly recommend at least updating to 2.3 Update 2 plus the latest patch update. There have been quite a few fixes to the managed-code compiler over the years.

    Updating to Visual COBOL 5 would be even better, but I realize organizations are often hesitant about major upgrades.

  • basic_trans inherits from XPBaseObject?

    Do you have a tool such as .NET Reflector to examine the assembly containing basic_trans to confirm that it has an accessible GetCollection<t>(String) method?

    I did some experimenting with generics to see if I could reproduce a similar problem without using DevExpress (which I'd rather not get into just for the purpose of investigating this), but couldn't find any issues. But I'm using Enterprise Developer 5.0.

  • .NET Reflector found the method in XPBaseObject which my class inherits from.

    I can also type "invoke" in the Visual COBOL editor and I am prompted with "GetCollection[]" which is defined as XPBaseObject::GetCollection[T](propertyName AS string) RETURNING DevExpress.Xpo.XPCollection[type T].

    I created a demo solution with a COBOL project and a C# project using the classes from a DevExpress document called "Relationships Between Objects".  I'm not able to include the link in this post.

    The C# project compiled fine.  The COBOL compiler couldn't find the method, when I included the parameter in brackets.  If I exclude the brackets, it finds the method but gives me a type incompatibility error, which is to be expected.

    I'll probably submit my demo solution to Micro Focus support and see what they say.  Maybe it's been fixed in a later version and they'll  tell us to update our Visual COBOL.  As you pointed out, we're running an old, unsupported version.

    I'm including the two COBOL classes below.  I think I got the C# to COBOL translation right.  What I'm trying to do is set up a one-to-many relationship between the Customer class and the Order class by using the Association attribute.  The GetCollection method returns a collection of objects automatically created by an association.

      $set ILUSING"DevExpress.Xpo"
           class-id XpoRelationships.Customer inherits type XPObject.
           working-storage section.
             01  fContactName              string.
             01  fPhone                    string.
           property-id ContactName string public.
           getter.
               set property-value to fContactName
           setter.
               invoke self::SetPropertyValue("ContactName", by reference fContactName, property-value)
           end property.
           property-id Phone string public.
           getter.
               set property-value to fPhone
           setter.
               invoke self::SetPropertyValue("Phone", by reference fPhone, property-value)
           end property.
           property-id  Orders type XPCollection [type Order] public
              attribute Association.
           getter.
             set property-value to GetCollection[type Order]("Orders")
           end property.
          
           end class.
     
     $set ILUSING"DevExpress.Xpo"
           class-id XpoRelationships.Order inherits type XPObject.
           working-storage section.
             01  fProductName              string.
             01  fCustomer                 type Customer.
           property-id ProductName string public.
           getter.
               set property-value to fProductName
           setter.
               invoke self::SetPropertyValue("ProductName", by reference fProductName, property-value)
           end property.
           property-id  Customer type Customer public
              attribute Association.
           getter.
             set property-value to fCustomer
           setter.
             invoke self::SetPropertyValue("Customer", by reference fCustomer, property-value)
           end property.
           end class.

     

     

     

     

     

     

  • Just as an added note, we installed Visual COBOL 4.0 onto a test machine and get the same error.

  • Hi Phil,

    I see that you opened up SI #3215786 for this issue.

    I installed the DevExpress Trial version on my system and tested this against the latest Visual COBOL product 5.0 PU4 and the error still occurs.

    We will create an RPI for it and submit it to Development.

    Thanks.