Why the FormInt64Control created by new() does not have method value?

I want to know why the FormInt64Control cread by new() does not have method value. For example when I run this code:

static void NewControlTest(Args _args)

{

FormInt64Control FormInt64Control;

FormInt64Control = new FormInt64Control();

FormInt64Control.value(5);

info(FormInt64Control.valueStr());

}

it will end with:

Object object does not have have method ‘value’.

Stack trace …

When the same thing is created on existing form using existing design (in run() for example).

formInt64Control = formGroupControl.addControl(FormControlType::Int64, “”);

formInt64Control.value(5);

will run without problem. I would like to know how it is possible and how it is working behind.



If you look at Value property in debugger, you’ll see that it contains an Object instance in the first case and a FormInt64Control instance in the other cases. And Object class really doesn’t have any value() method.

It’s strange, without doubt, and it again shows that type control in X++ has its flaws. It seems that you should never use the constructor directly, even if it throws no error. Instead of that, create an instance by addControl().