Thursday, December 18, 2008

How to pack and unpack an array object holding other objects

If you want to pack an array with values of the types class, the classes held by the array must also be able to be packed.

Therefore the class that's in the array must implement SysPackable and you must implement the pack and unpack methods. 
I presume you are familiar with these methods.

Furthermore the class must have a static method called create. For example:
static public MyValueClass create(Container _packedClass)
{        
    MyValueClass  myValueClass;        
    ;         
    myValueClass = new MyValueClass();
    myValueClass.unpack(_container);
    return myValueClass;
}

 

This posting is provided "AS IS" with no warranties, and confers no rights.

1 comment:

somanna said...

If you want to pack an array with values of the types class, the classes held by the array must also be able to be packed.

Therefore the class that's in the array must implement SysPackable and you must implement the pack and unpack methods.
I presume you are familiar with these methods.

Furthermore the class must have a static method called create. For example:
static public MyValueClass create(Container _packedClass)
{
MyValueClass myValueClass;
;
myValueClass = new MyValueClass();
myValueClass.unpack(_container);
return myValueClass;
}

Activating a custom toolbar

In my previous post I gave a short example of how you can use a regular form to create a new custom toolbar.

That was the easy part. You would of course want to make it easy to access the toolbar and with this post I will describe a suggestion for doing that.

Customized short cut keys is not really something you can setup in AX, so I suggest we put access to the toolbar in the menu strip under the Tools menu. We can add a menu item to start up the form to this menu very easily.

We only want one toolbar open at any time, so we’re going to have to keep track of the opened toolbar. We will use the global cache to do that.

First create a class to open the toolbar form and control that only one toolbar is open at any time:

class aaaToolbar
{
}



private void openToolBar()
{
FormRun formRun;
Args args;
;
formRun = infoLog.globalCache().get(formStr(aaaToolBar), '1', formRun); // Lookup in the global cache

if (!formRun)
{
args = new Args();
args.name(formstr(aaaToolbar)); // Toolbar form name
formRun = new FormRun(args);
formRun.run();
formRun.detach();

infoLog.globalCache().set(formStr(aaaToolBar), '1', formRun); // Add to the global cache
}
else
{
formRun.setActive();
}
}



static void main(Args _args)
{
aaaToolbar toolbar; ;



toolbar = new aaaToolbar(); toolbar.openToolBar();
}


(Please note that AX best practice would be to create a menu item for the form too and call that rather than calling FormRun directly)

Create a menu item to start the class. The menu item must have, at least, the following properties:
Type
Display

Name
aaaToolbar

Label
Show toolbar

Class
Class

Object
aaaToolbar


Add the new menu item to the GlobalToolsMenu menu. You must restart AX in order to see it appear in the menu in the menu strip.

Finally add code to the toolbar form to remove it from the global cache when it is closed:

public void close()
{
super();
infoLog.globalCache().remove(formStr(aaaToolBar), '1');
}

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...