Changing AOT properties from code

June 23, 2009 No comment

When you want to it is possible to change AOT properties from code.

The first you need to do, is finding the treenode you want to modify:

1
2
3
4
5
#AOT
#Properties
TreeNode                        node = TreeNode::findNode(#TablesPath);
;
node = node.AOTfindChild("SysUserInfo");

When you want to get a property you can simply check this by using the method AOTGetProperty. In the macro Properties you have a macro for evry property.

1
info(node.AOTgetProperty(#PropertyCreatedby));

When you want to change the property you use the method AOTSetPropery.

1
node.AOTsetProperty(#PropertyCreatedby, #PropertyValueYes);

Now you just have to save the changes you made by calling the save method and releasing the memmory held by the TreeNode. The garbage collector cannot clean up objects it self.

1
2
3
node.AOTsave();
node.treeNodeRelease();
node = null;

So if you put all this code in a job you get:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
static void JeDoe_testTreeNode(Args _args)
{
    #AOT
    #Properties
    TreeNode                        node = TreeNode::findNode(#TablesPath);
    ;
    node = node.AOTfindChild("SysUserInfo");
    info(node.treeNodePath());
    info(node.AOTname());
 
    info(node.AOTgetProperty(#PropertyCreatedby));
 
    node.AOTsetProperty(#PropertyCreatedby, #PropertyValueYes);
 
    node.AOTsave();
    node.treeNodeRelease();
    node = null;
}

Extra:

You can also Create/Modify/Delete code in mothdes from code. For doing this you wil need to use the variable MemberFunction. You simply Find the TreeNode-path from the method you want to modify and put it into the MemberFunction variable. The you can get/set the source code with AOTGetSource/AOTSetSource. After changing the code you just need to save and compile with AOTSave & AOTCompile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TreeNode                        dataSourceNode;
TreeNode                        formNode;
MemberFunction                  method;
str                             dataSourceMethodPath    = ...; // Path to the method you want to modify
str                             formPath                = ...; // Path to the form you want to modify
;
formNode            = TreeNode::findNode(formPath);
dataSourceNode      = TreeNode::findNode(dataSourceMethodPath);
if(dataSourceNode && formNode)
{
    method          = dataSourceNode.AOTfindChild(#Active);
    if (!method)
    {
        dataSourceNode.AOTadd(#Active);
        method      = dataSourceNode.AOTfindChild(#Active);
    }
    method.AOTsetSource(method.AOTgetSource() + "// Some comment", false);
    formNode.AOTsave();
    formNode.AOTcompile(1);
}