将 smmOpportunityTable 设置为 common 时 Dynamics ax 2012 编译器警告
Dynamics ax 2012 compiler warning when seting smmOpportunityTable to common
A class 可以接收 VendTable、CustTable 或 smmOpportunityTable 记录。
例如,通常会收到一条 CustTable 记录,而一个新的需求会使 smmOpportunityTable 发挥作用,所以我使用一条通用记录通过这段代码捕获它:
(在设置 custTable 记录的代码中前面发生了一些其他事情)。
commonParty = custTable.RecId != 0 ? custTable : smmOpportunityTable;
问题是,上面这行代码给出了编译警告“Operand types are not compatible with the operator.”;在 smmOpportunityTable 上出错。
我的问题是,为什么我不能将 smmOpportunityTable 的实例设置为 common?当然它的基本类型很常见?关于如何解决警告的任何想法?
我正在 Dynamics Ax 2012 R1 中开发。
警告实际上只是因为编译器似乎错误地处理了三元运算符的使用。
要删除警告,您可以重写为:
if (custTable)
commonParty = custTable;
else
commonParty = smmOpportunityTable;
if (custTable)
等同于 if (custTable.RecId != 0)
。它实际上只是检查 RecId
字段是否已填充。
我可能对您在代码中尝试做的事情感到困惑,但对于作业的另一面,惯例通常如下:
switch (common.TableId)
{
case tableNum(CustTable):
custTable = common as CustTable;
break;
case tableNum(smmOpportunityTable):
smmOpportunityTable = common as smmOpportunityTable;
break;
default:
throw error(strFmt(Error::wrongUseOfFunction(funcName())));
}
A class 可以接收 VendTable、CustTable 或 smmOpportunityTable 记录。
例如,通常会收到一条 CustTable 记录,而一个新的需求会使 smmOpportunityTable 发挥作用,所以我使用一条通用记录通过这段代码捕获它:
(在设置 custTable 记录的代码中前面发生了一些其他事情)。
commonParty = custTable.RecId != 0 ? custTable : smmOpportunityTable;
问题是,上面这行代码给出了编译警告“Operand types are not compatible with the operator.”;在 smmOpportunityTable 上出错。
我的问题是,为什么我不能将 smmOpportunityTable 的实例设置为 common?当然它的基本类型很常见?关于如何解决警告的任何想法?
我正在 Dynamics Ax 2012 R1 中开发。
警告实际上只是因为编译器似乎错误地处理了三元运算符的使用。
要删除警告,您可以重写为:
if (custTable)
commonParty = custTable;
else
commonParty = smmOpportunityTable;
if (custTable)
等同于 if (custTable.RecId != 0)
。它实际上只是检查 RecId
字段是否已填充。
我可能对您在代码中尝试做的事情感到困惑,但对于作业的另一面,惯例通常如下:
switch (common.TableId)
{
case tableNum(CustTable):
custTable = common as CustTable;
break;
case tableNum(smmOpportunityTable):
smmOpportunityTable = common as smmOpportunityTable;
break;
default:
throw error(strFmt(Error::wrongUseOfFunction(funcName())));
}