以下は、RunBase クラスを使用して簡単なダイアログを作成する方法の AX 2009 の例です。その中で、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());
}
}
通常、このシナリオでは、実行する必要があるロジックはクラスの run メソッドに配置され、[OK] ボタンがクリックされた場合にメインから呼び出されます。run メソッドはインスタンス メソッドになるため、parm メソッドがダイアログのフィールドの値にアクセスする必要がなくなります。