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
formRun.controlMethodOverload(true);
formRun.controlMethodOverloadObject(this);
// here override Sorting on all datafields added on the grid
this.overrideSortMethodOnDatafields(form);
//<--
formRun.init();


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(_formBuildDataSource.id(), 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 = iterator.next();
//take the first datafield
controlNode = iterator.next();
this.setCompilerWarningsOff();
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
newMethod.AOTcompile();
controlNode = iterator.next();
}
this.setCompilerWarningsOn();
}
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,custtable.data());
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.

Monday, July 28, 2008

DAX Help Creation Quick Information

It may be a very good idea to provide your customer with a full documentation about customisations made during the project in .chm file - standard format of Microsoft Dynamics AX help. It can be distributed and maintained easier and more flexible.

By virtue of Arijit Basu (DAX Guy) blog I created this very simple help project DAXHelpCreation.chm which can be decompiled and analysed in order to create your own help project.

It includes DAX Guy posting itself as the first article, then my short notes about .html files preparation and, finally, the entire project from Microsoft Help Kit.

Create the f. manual!

Thursday, July 17, 2008

AppDoc Bug: HTMLHelpFile property is unavailable in DAX2009

As far as I see neither this property nor HTMHelpTopic are available for newly created objects in Application Documentation branch of AOT even if I set HTMLFileEnabled to Yes.

The only cure is to restart the client.

Moreover, after that if you first choose anything but your newly created object in Application Documentation branch (if you e.g. search for it by typing its first letters of the name) or the current element you are working with in the branch loses the focus that is the case - you now cannot change these properties.


Correct me, please, if I missed something.

Wednesday, July 16, 2008

Universal Field Changer (xpo project)

Sometimes we need to change the values of a group of records in a table at once. I hope this project will be useful in this meaning.

It allows you to choose a table with excluding some of them. After that you can browse the table and open it directly in AOT.

You then can choose a field from the table excluding or not system fields and look through existing values to pick up or just input a new value.

Change function works only with a result of the query which text you can see as well. No checks nor validatings!

Use it at your own risk and do not forget how it can be dangerous for the system to change their fields directly!

The project is moved to. Tested on version 4.0.

Next, I am going to implement it as a class.

Wednesday, July 2, 2008

Go to the main table option

It was something new for me.

To have Go to the main table option working properly you should create a form and appropriate Display Menu Item for the table with the same name.

Otherwise you will get a message like this:

No object specified on menu item XXXX_TableName