AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 26.01.2007, 05:51   #1  
Blog bot is offline
Blog bot
Участник
 
25,631 / 848 (80) +++++++
Регистрация: 28.10.2006
Kashperuk Ivan: Description of ClassBuild class:Today I want to ...
Источник: http://kashperuk.blogspot.com/2006/1...ing-class.html
==============

Description of ClassBuild class:

Today I want to write about using the class ClassBuild.
A collegue of mine recently used this class for extending Axapta's IDE, so I decided you all should know about this class too.

OK, let's start with the declaration of the class:
It's simple, the class isn't extending any other class, a variable of type class ClassNode is declared together with a macro #aot - it contains pathes to all the objects in the AOT
X++:
X++:
public class ClassBuild
{
    ClassNode classNode;
    #aot
}
The class contains the following methods:
void new(str _name, boolean _allowExisting = true) - this is the constructor of the class

void addMemberVariable(str _variableType, str _variableName) - this method is used to create a variable declaration in a class

TreeNode addMethod(str _name, str _source) - this method is used to create new methods and set their source code

void addSourceToMethod(str _memberFunction, str _addSource) - using this method we can set the source code of an existing method

ClassNode classNode() - this method returns a ClassNode object pointing to the created class

public MemberFunction getMethodImplementation(str _methodName, boolean _includeParents) - the method return a MemberFunction object, which has methods to edit or view the source code of the specified method of the class

public str name() - the method returns the name of the created class

TreeNode overrideMethod(str _name, str _newSource = '') - this method is used to override the method of the parent class in case one exists


I will explain how the class should be used on a specific example: (click the image to enlarge)


Explanation:
In line 6 we create a new Object of class ClassBuild. Into the constructor we pass the name of the class we want to create and an optional paramter, which controls the execution of code in case the class already exists in the AOT.
After the execution of this line the class already exists.
After that we add a method test() to our class and set the source code for this method.
Then we add a member variable of our class, and will try using this variable in a second method we create - test2(). You can see that here I did this in 2 steps on purpose - to show the way you can use the method addSourceToMethod().
OK, now all the methods are created and we have to compile our class. For this we can use the method AotCompile() of class TreeNode, which we access through the method classNode of the created class.
Now, to see how 2 other methods work, we show a message dialog with the name of the class being created and the source code of one of the methods.

Then, just to show you the class works and is ready to be used, we can call one of its methods for execution.
For this, we use the class DictClass and its methods, but I will not discuss it in this post.

That's it. Try running the attached job and see how it works!
Attachment: Job17.xpo


There is also another way of creating the same class - by using the UtilElements table: (code provided by AndyD from AxForum)

UtilIdElements utilIdElements;
TreeNode tn;
;
utilIdElements.initValue();
utilIdElements.Name = "newClass";
utilIdElements.recordType = UtilElementType::Class;
utilIdElements.insert();
tn = xUtilIdElements::getNode(utilIdElements);
tn.AOTcompile(1);
tn.AOTsave();



See also: Classes\FormBuild, Classes\DictClass


Источник: http://kashperuk.blogspot.com/2006/1...ing-class.html
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Kashperuk Ivan: SysInfoAction class description - Improve your Infolog Blog bot DAX Blogs 0 17.09.2008 03:23
Kashperuk Ivan: SysFormEnumComboBox - class allowing to show only some of the values for a comboBox Blog bot DAX Blogs 0 28.04.2008 19:05
Kashperuk Ivan: List panels in Dynaics AX - a short description of SysListPanel class Blog bot DAX Blogs 1 21.10.2007 22:51
Kashperuk Ivan: A bug in validation of methods' access modifiers and class abstract modifier Blog bot DAX Blogs 0 27.06.2007 21:40
Говорят вышел SP2 для Axapta 3. Кто нибуть что знает на эту тему? soin DAX: Прочие вопросы 10 13.10.2003 10:43

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 12:41.