【问题标题】:Dynamics ax 2012 compiler warning when seting smmOpportunityTable to common将 smmOpportunityTable 设置为 common 时 Dynamics ax 2012 编译器警告
【发布时间】:2015-03-06 08:01:48
【问题描述】:

类可以接收 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 进行开发。

【问题讨论】:

    标签: axapta dynamics-ax-2012


    【解决方案1】:

    警告实际上只是因为编译器似乎错误地处理了三元运算符的使用。

    要删除警告,您可以重写为:

    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())));
    }
    

    【讨论】:

    • 是的,我确实写了开关来消除警告。仍然对编译器可以将 custTable 解释为通用表而不是 smmOpportunities 表感到恼火......不过还是谢谢!
    • 你可以试试用括号commonParty = (custTable.RecId != 0) ? custTable : smmOpportunityTable;看看是否可行?
    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 2012-06-01
    • 2013-02-28
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多