Search code examples
axaptamicrosoft-dynamicsx++dynamics-ax-2009

How to override FormControl method at RunTime?


I'm trying to make some kind of validation framework in Dynamics AX 2009. And I need to override some FormControl methods at runtime.

For example this is MyValidationTool class:

void applyValidation(FormControl _control)
{
    _control.overideMethod("modified", this.validate());
}

So I can use it in any form object like this:

void init()
{
    MyValidationTool validationTool = new MyValidationTool();
    ;

    validationTool.applyValidation(userNameStringEdit);
}

Maybe I completely wrong at what I want. But I still will appreciate the answer of how I can override methods programmatically using X++.


Solution

  • Have a look at the tutorial form tutorial_Form_AddControl
    What you have to do in short is create methods in the form of controlName_methodToOverride, e.g. myTxt_validate.
    If you want to override the methods for runtime controls not directly on the form but on a separate object, take a look at the form's method controlMethodOverloadObject - with that method you can specify the object on which the methods of form controlName_methodToOverride will be invoked if possible.