HI All,
I am trying to add a method to form dynamically, first i check if the method exists, if found i will delete that method and create new one, if not found i create new method simply. here is the code i am using. The following code is checking for the method existence and if not found its creating new method. BUT when method exists, it is not doing the way i wanted it simply stops and crashes the ax. please help me in correcting the following thanks in advance
private void findOrCreateTimeStamp(
SysVersionControlTmpItem _item)
{
str timeStamp;
str methodSource;
UtilElements utilElement;
FormBuild formBuild;
MemberFunction method;
Object formRun;
Args args = new Args();
SysVersionControlTmpItem item = _item;
str methodName = "csGetVersion";
int time = timenow();
TreeNode treeNode = TreeNode::findNode(item.ItemPath);
utilElement = treeNode.utilElement();
timeStamp = date2Str(
today(),
321,
DateDay::Digits2,
DateSeparator::Slash,
DateMonth::Digits2,
DateSeparator::Slash,
DateYear::Digits4,
DateFlags::None);
timeStamp = timeStamp + "_" +
num2str0(time div 3600, 2, 0, 0, 0) + ":" +
num2Str0(time mod 3600 div 60, 2, 0, 0, 0) + ":" +
num2Str0(time mod 3600 mod 60, 2, 0, 0, 0);
methodSource = "public static str csGetVersion()\n{\n return '" +timeStamp+ "';\n}";
if (utilElement.recordType == UtilElementType::Form)
{
args.name(utilElement.name);
formRun = ClassFactory.formRunClass(args);
formBuild = new FormBuild(utilElement.name, true);
if (formHasMethod(formRun, methodName))
{
//Delete existing method and create new method here, since the method already exists in the component.
treeNode = formBuild.form().AOTfindChild('methods');
method = formBuild.form().AOTfindChild('methods').AOTfindChild(methodName);
method.AOTdelete();
formBuild.addMethod(
methodName,
methodSource);
}
else
{
//Make a new method here since it does'nt exist in the component.
formBuild.addMethod(
methodName,
methodSource);
}
formBuild.form().AOTcompile();
formBuild.form().AOTsave();
}
}