Thursday, August 14, 2008

Method Overloading

Sometimes we need to change the standard behaviour of form controls. It is not a big deal when when it concerns overriding form controls' methods in design time in AOT. But when it comes to doing that dynamically it may not be as simple as a piece of cake.

From the beginning the goal was to make sorting functionality on the grid created by SysTableLookup class impossible for the user. It might have been a good solution to change the code like the following

formRun = classfactory.formRunClass(args);
form = formRun.form();
// allow the class to react on the form's events
// here override Sorting on all datafields added on the grid

but this class creates Datafields on the grid and names for these FormBuildControls are assigned by Axapta in an unpredictable way. So it was not possible to create methods like FormNameControlName_Sort().

formBuildControl = _formBuildGridControl.addDataField(, fieldId);

There is another way to do that. With the big help of AxForum I created the class SysTableLookupWithoutSort which extends the system class with the new key method:

protected void turnSortingOff(Form _form)
int i;
TreeNode gridNode, controlNode, methodsNode;
MemberFunction newMethod;
str source = 'public int sort(SortOrder _sortDirection){; return 0;}';
TreeNodeIterator iterator;
gridNode = _form.AOTfindChild('Designs');
gridNode = gridNode.AOTfindChild('Design');
gridNode = gridNode.AOTfirstChild();
iterator = gridNode.AOTiterator();
controlNode =;
//take the first datafield
controlNode =;
for (i = 1; i <= conlen(lookupItems); i++)
//override sort method
methodsNode = controlNode.AOTfindChild('Methods');
newMethod = methodsNode.AOTadd('sort');
newMethod.AOTsetSource(source, false);
//compile the method
controlNode =;
Just to show how this class works in comparison with the standard class (without the sorting functionality) I also added DemoMethodOverloadingClass class.

Moreover this class shows how various FormControls can be added on a form from scratch and their methods can be overridden from code as well: Button, StringEdit, Datafields.

You can import this DemoMethodOverloadingClass project to make your experiments with dynamic programming.

memory leak in Axapta 3.0

Recently having got an error message after using AOS for batch processing I started digging this problem and finally found out that was described in Fixlist of Service Pack 5.
(Problem #1748 Processing some X++ code constructions resulted in a memory leak.)

You may see the same error by creating a job like the following one as it was suggested in Fixlist in order to reproduce the message. I just increased the number of iteration and an info to see the progress.

static void MemoryLeakTest(Args _args)
container custcont;
int loop;
Custtable custtable;
select custtable;
custcont = conins(custcont,1,;
for(loop = 1; loop <= 100000; loop++)
infolog.add(exception::Info, strfmt('loop %1', loop));
[custtable] = conpeek(custcont,1); //memory leak

Monday, August 4, 2008

Class Universal Field Changer (xpo project)

As I promised before I realized this project as a class. It was full of fun and incredible adventurous.

But anyway here is the Class_UniversalFieldChanger which provides you with the same functionality but it does not require importing something else like tables.

Also I am going to add my comments regarding using temporary tables, creating them from code, adding them methods dynamically and other tricks.