Monday, December 15, 2014

Form control type at run-time

This shows how to get the type of a form control at run-time. The code iterates through the controls in a field group and checks each control for it's type. 

    FormControl fc;
    int         i;

    // ...
   
    for(i=1; i <= FieldGroupName.controlCount(); i++)
    {
        fc = FieldGroupName.controlNum(i);
        if(SysDictClass::is(fc, classNum(FormStringControl)))
        {
            info(strFmt("%1 %2", fc.name(), fc.type()));
        }
    }
If you do this in Dynamics AX 2012 you will get the following warning:

The SysDictClass::is method is obsolete. Use the IS operator instead.


The new syntax is:

if(fc is FormStringControl)

No comments:

Post a Comment