Unexpected Behavior in a returned List

Hi,

I am using Managed COBOL on .NET and I fetch a list of customers from the Oracle Database and then add them to a list of type List[Customer]

the problem is at the debug everything is okay and the list is 100% filled with the right objects with the right values and when it's returned to be set to another list on the other also managed project - I've separated the business logic from the desktop view in two projects- the result is having the list filled with the object of the last entry of the list that was originally fetched for example if the list has the values 

1

2

3

4

the result of returning the list is 

4

4

4

4

and I repeat at debug time every thing is okay at the business logic project!!

could anyone please tell me what's going on ??

Best Regards

Tags:

Parents
  • Verified Answer

    Dear Chris,

    Tank you very much. I'd figured it, the problem was that I just change the attributes of an object at the local-storage section of the method so I keep changing the same object and adding it to the list which practically means that I just add a new reference to the same object to the list, so I just changed my code to add a new object with the newly fetched values dynamically and I wrote a constructor that takes the record as an argument so it now looks like:

    write customers-list from new Entities.Customer(customer-record)

    and as usual fro COBOL it just works!!

    Kind Regards

Reply
  • Verified Answer

    Dear Chris,

    Tank you very much. I'd figured it, the problem was that I just change the attributes of an object at the local-storage section of the method so I keep changing the same object and adding it to the list which practically means that I just add a new reference to the same object to the list, so I just changed my code to add a new object with the newly fetched values dynamically and I wrote a constructor that takes the record as an argument so it now looks like:

    write customers-list from new Entities.Customer(customer-record)

    and as usual fro COBOL it just works!!

    Kind Regards

Children
No Data