Axapta 在ax 2012组件中动态添加方法
我想在ax 2012中向组件动态添加一个方法,如何通过代码实现这一点?有可能吗?这是我写的一份工作,展示了做你想做的事情的多种不同方式:Axapta 在ax 2012组件中动态添加方法,axapta,dynamics-ax-2012,dynamics-ax-2012-r2,dynamic-method,Axapta,Dynamics Ax 2012,Dynamics Ax 2012 R2,Dynamic Method,我想在ax 2012中向组件动态添加一个方法,如何通过代码实现这一点?有可能吗?这是我写的一份工作,展示了做你想做的事情的多种不同方式: static void Job79(Args _args) { TreeNode treeNode = TreeNode::findNode(@'\Classes\Activities'); SysDictClass sysDictClass = new SysDictClass(treeNode.applObjectId(
static void Job79(Args _args)
{
TreeNode treeNode = TreeNode::findNode(@'\Classes\Activities');
SysDictClass sysDictClass = new SysDictClass(treeNode.applObjectId());
FormRun formRun = new FormRun(new Args(formStr(AifAction)));
Form form = new Form(formStr(AifAction));
ClassBuild classBuild;
SysDictTable sysDictTable = new SysDictTable(tableNum(AccountSumMap)); // Maps are treated like tables
SysDictMethod sysDictMethod;
int i;
MemberFunction method;
str methodSource = 'public static str getTime()\n{\n\treturn "3/3/2015";\n}';
// Find if class has a method
if (sysDictClass.hasObjectMethod('delete'))
{
info("Found object method delete");
}
if (sysDictClass.hasStaticMethod('main'))
{
info("Found static method main");
}
// Find if form has a method
if (formHasMethod(formRun, 'init'))
{
info("Found form method 'init'");
}
if (form.AOTfindChild('methods').AOTfindChild('refreshGrid') != null)
{
info("Found 'refreshGrid' method on AifAction");
}
if (sysDictClass.hasStaticMethod('getTime') == false)
{
classBuild = new ClassBuild(sysDictClass.name());
treeNode = classBuild.addMethod('getTime', methodSource);
if (classBuild.classNode().AOTcompile())
{
classBuild.classNode().AOTsave();
info("Added method getTime, compiled, and saved");
}
else
{
info(strFmt("Unable to compile method 'getTime' with source code '%1', restoring class...", treeNode.AOTgetSource()));
// Delete the non-compiling method
if (treeNode)
treeNode.AOTdelete();
classBuild.classNode().AOTsave();
}
}
else
{
info("Method 'getTime' already exists");
}
if (sysDictTable.isMap())
{
if (sysDictTable.doesMethodExist('getTime') == false)
{
treeNode = sysDictTable.treeNode().AOTfindChild('methods').AOTadd('getTime');
method = sysDictTable.treeNode().AOTfindChild('methods').AOTfindChild('getTime');
method.AOTsave();
method.AOTsetSource(methodSource, true);
method.AOTsave();
if (sysDictTable.treeNode().AOTcompile())
{
sysDictTable.treeNode().AOTsave();
info(strFmt("Added 'getTime' to AccountSumMap"));
}
else
{
info(strFmt("Unable to compile method 'getTime' with source code '%1', restoring class...", treeNode.AOTgetSource()));
// Delete the non-compiling method
if (treeNode)
treeNode.AOTdelete();
sysDictTable.treeNode().AOTsave();
}
}
}
}
下面是我写的一份工作,它展示了一系列不同的方法来做你想做的事情:
static void Job79(Args _args)
{
TreeNode treeNode = TreeNode::findNode(@'\Classes\Activities');
SysDictClass sysDictClass = new SysDictClass(treeNode.applObjectId());
FormRun formRun = new FormRun(new Args(formStr(AifAction)));
Form form = new Form(formStr(AifAction));
ClassBuild classBuild;
SysDictTable sysDictTable = new SysDictTable(tableNum(AccountSumMap)); // Maps are treated like tables
SysDictMethod sysDictMethod;
int i;
MemberFunction method;
str methodSource = 'public static str getTime()\n{\n\treturn "3/3/2015";\n}';
// Find if class has a method
if (sysDictClass.hasObjectMethod('delete'))
{
info("Found object method delete");
}
if (sysDictClass.hasStaticMethod('main'))
{
info("Found static method main");
}
// Find if form has a method
if (formHasMethod(formRun, 'init'))
{
info("Found form method 'init'");
}
if (form.AOTfindChild('methods').AOTfindChild('refreshGrid') != null)
{
info("Found 'refreshGrid' method on AifAction");
}
if (sysDictClass.hasStaticMethod('getTime') == false)
{
classBuild = new ClassBuild(sysDictClass.name());
treeNode = classBuild.addMethod('getTime', methodSource);
if (classBuild.classNode().AOTcompile())
{
classBuild.classNode().AOTsave();
info("Added method getTime, compiled, and saved");
}
else
{
info(strFmt("Unable to compile method 'getTime' with source code '%1', restoring class...", treeNode.AOTgetSource()));
// Delete the non-compiling method
if (treeNode)
treeNode.AOTdelete();
classBuild.classNode().AOTsave();
}
}
else
{
info("Method 'getTime' already exists");
}
if (sysDictTable.isMap())
{
if (sysDictTable.doesMethodExist('getTime') == false)
{
treeNode = sysDictTable.treeNode().AOTfindChild('methods').AOTadd('getTime');
method = sysDictTable.treeNode().AOTfindChild('methods').AOTfindChild('getTime');
method.AOTsave();
method.AOTsetSource(methodSource, true);
method.AOTsave();
if (sysDictTable.treeNode().AOTcompile())
{
sysDictTable.treeNode().AOTsave();
info(strFmt("Added 'getTime' to AccountSumMap"));
}
else
{
info(strFmt("Unable to compile method 'getTime' with source code '%1', restoring class...", treeNode.AOTgetSource()));
// Delete the non-compiling method
if (treeNode)
treeNode.AOTdelete();
sysDictTable.treeNode().AOTsave();
}
}
}
}
上述方法是参考之前的答案和其他专业人士创建的。它首先验证类中是否存在该方法。如果找到该方法,它将覆盖其他方法并创建新方法。对于其他元素,如表、表单和映射,我们可以以类似的方式实现
上述方法是参考之前的答案和其他专业人士创建的。它首先验证类中是否存在该方法。如果找到该方法,它将覆盖其他方法并创建新方法。对于其他元素,如表、表单和映射,我们可以以类似的方式实现。不确定“组件”是什么意思,也不确定您实际试图实现什么,但您是否查看了AX 2012()中事件处理的可能性?实际上,这里的组件指的是类、表、表单或映射。我需要动态添加一个方法,如public static str getTime(){ret“time”;}组件在这里引用AOT中的类、映射、表或表单,我需要检查该组件中是否存在名为getTime()的方法,如public static str getTime(){ret 3/3/2015”;}的方法,如果未找到,则在该组件中创建上述方法。例如:我们在AOT中有一个名为ImageListAppl的类,我需要检查名为getTime()的方法是否存在,如果没有找到,则在该类中动态创建getTime()方法。这同样适用于其他组件,如表、地图、表单。请看一看类
ClassBuild
,这会给您一些想法。当我找到时间的时候,我会用一些示例代码来写一个答案。我不确定“组件”是什么意思,或者你实际上想完成什么,但是你有没有看一下AX 2012()中事件处理的可能性?实际上这里的组件指的是类、表、表单或映射。我需要动态添加一个方法,如public static str getTime(){ret“time”;}组件在这里引用AOT中的类、映射、表或表单,我需要检查该组件中是否存在名为getTime()的方法,如public static str getTime(){ret 3/3/2015”;}的方法,如果未找到,则在该组件中创建上述方法。例如:我们在AOT中有一个名为ImageListAppl的类,我需要检查名为getTime()的方法是否存在,如果没有找到,则在该类中动态创建getTime()方法。这同样适用于其他组件,如表、地图、表单。请看一看类ClassBuild
,这会给您一些想法。当我找到时间时,我会用一些示例代码写一个答案。