2

The Problem:

  • I have a list with Objects as elements.
  • I use enumerator to loop over the list.
  • While looping I assign elements to a variable object with the same type as the element.
  • When I call a method on the object, but I get the following error-message:

MyClass object not initialized.

I think I must cast, but don't know how to do this in Dynamics AX.

I develop in MS Dynamics AX 2012.

MyExampleDataContract exampleDataContract = new MyExampleDataContract();
while (listEnumerator.moveNext())
{
    exampleDataContract = listEnumerator.current();
    info(exampleDataContract.parmCustomerId()); //This gives an error.
}
Tassisto
  • 9,877
  • 28
  • 100
  • 157

2 Answers2

2

A list element can be null.

List l = new List(Types::Class);
;
l.addEnd(null);
info(int2str(l.elements()));
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
1

The solution was: Before inserting elements in the list they should be instantiated first.

for (counter = 1; counter <= 3; counter++)
{
    exampleDataContract = new MyExampleDataContract(); // This is what I missed :)
    exampleDataContract.init("DEV-000000000" + int2str(counter));
    myList.addEnd(exampleDataContract);
}
Tassisto
  • 9,877
  • 28
  • 100
  • 157