我發現了幾個帖子和周圍的淨談論對話框驗證表單字段的文章,但沒有我發現的例子似乎正常工作。Axapta的對話框驗證
有人可以發佈一個完整,簡潔的x ++代碼示例,它生成一個包含單個文本字段的對話框,對其執行簡單驗證(如果text =「abc」),並關閉窗口(返回字段值)如果驗證通過,或者在驗證失敗的情況下生成Infolog警告而不關閉對話框。
對於我們這些剛剛在X ++開始,我認爲這將是一個偉大的起點,有一個實際的工作示例的基礎上。
謝謝!
我發現了幾個帖子和周圍的淨談論對話框驗證表單字段的文章,但沒有我發現的例子似乎正常工作。Axapta的對話框驗證
有人可以發佈一個完整,簡潔的x ++代碼示例,它生成一個包含單個文本字段的對話框,對其執行簡單驗證(如果text =「abc」),並關閉窗口(返回字段值)如果驗證通過,或者在驗證失敗的情況下生成Infolog警告而不關閉對話框。
對於我們這些剛剛在X ++開始,我認爲這將是一個偉大的起點,有一個實際的工作示例的基礎上。
謝謝!
這裏是如何建立使用RunBase類一個簡單的對話框2009年AX的例子。在其中創建一個名爲DialogExample的類並從RunBase派生。爲了顯示對話框,你只需要運行類,但通常這是通過在類上指定一個MenuItem來完成的。
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按鈕此方案的邏輯。由於run方法是一個實例方法,因此無需使用parm方法來訪問對話框上的字段值。
我知道這是一個老問題,但也應注意到,對於AX發展的世界開始了人,還有在AOT偉大的工作代碼示例,尋找具有前綴的窗體和類「 Tutorial_」。
Tutorial_RunBaseForm是在AOT一類,讓你正是你需要的。
感謝您抽出後這個極好的響應時間。它完美的作品。 – Brad 2009-11-24 14:46:33