题
我发现了几个帖子,并谈到在对话框中验证表单字段周围的网文章,但没有我发现的例子似乎正常工作。
有人能后的生成包含单个文本字段的对话X ++代码一个完整的,简明的例子中,执行简单的验证(如果文本=“ABC”)就可以了,并且或者关闭窗口(返回字段的值),如果验证通过或不如果验证失败关闭对话框生成信息日志警告。
对于我们这些刚刚开始在X ++,我认为这将是一个伟大的起点,有一个实际的工作示例的基础上。
谢谢!
解决方案
下面是如何建立使用RunBase类一个简单的对话框2009 AX的例子。在这里面我创建一个名为DialogExample类和派生RunBase。要显示该对话框,你只需要运行的类,但通常这会通过在类指着一个菜单项来完成。
public class DialogExample extends RunBase
{
DialogField dialogName;
Name name;
#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
name
#ENDMACRO
}
Object dialog()
{
Dialog dialog = super();
;
// Add a field for a name to the dialog. This will populate the field with
// any value that happens to be saved in name from previous uses of the
// dialog.
dialogName = dialog.addFieldValue(TypeId(Name), name);
return dialog;
}
boolean getFromDialog()
{
;
// Retrieve the current value from the dialog.
name = dialogName.value();
return true;
}
boolean validate(Object _calledFrom = null)
{
boolean isValid;
isValid = super(_calledFrom);
// Perform any validation nessecary.
if (name != 'abc')
{
isValid = checkFailed('Name is not equal to abc') && isValid;
}
return isValid;
}
Name parmName()
{
;
return name;
}
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
public boolean unpack(container _packedClass)
{
int version = conpeek(_packedClass, 1);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = _packedClass;
break;
default :
return false;
}
return true;
}
public static void main(Args args)
{
DialogExample DialogExample;
;
dialogExample = new dialogExample();
// Display the dialog. This only returns true if the the user clicks "Ok"
// and validation passes.
if (dialogExample.prompt())
{
// Perform any logic that needs to be run.
info(dialogExample.parmName());
}
}
典型地,在需要被运行将被置于运行方法的类,然后叫入从主如果点击OK按钮此方案的逻辑。由于运行的方法是一个实例方法本摆脱的需要进行的parm方法来访问对话框上的字段的值。
其他提示
我知道这是一个老问题,但也应注意到,对于AX发展的世界开始了人,还有在AOT伟大的工作代码示例,寻找具有前缀“Tutorial_窗体和类”
Tutorial_RunBaseForm是在AOT一类,让你正是你需要的。
不隶属于 StackOverflow