Dynamics AX 中 runbuf 函数的更详细错误

More detailed error from runbuf function in Dynamics AX

我尝试构建某种 X++ 脚本执行器,因此尝试使用 runbuf 函数。 只要我传入的 X++ 代码有效,它就可以工作,但是当我传递无效代码时,它只会抛出一个错误,表明它无法编译代码,但没有进一步的细节。 例如,当我尝试以下代码时

runbuf('void dynAdd(int lhs, int rhs) { return lhs + rhs; }');

失败并出现错误

Unable to compile "void dynAdd(int lhs, int rhs) { return lhs + rhs; }".

有没有办法获得有关错误的更多信息?

提前致谢

您可以像这样使用 XppCompiler

static void DynamicXppTest(Args _args)
{
    str         dynamicXpp;
    int         result;
    XppCompiler xppCompiler;
    ;

    dynamicXpp = 'void dynAdd(int lhs, int rhs) { return lhs + rhs; }';

    // previous runbuf - style
    // 
    // result = runbuf(dynamicXpp, 3, 4);
    // info(strfmt("result = %1", result));

    xppCompiler = new XppCompiler();
    if (xppCompiler.compile(dynamicXpp))
    {
        result = xppCompiler.execute(3, 4);
        info(strfmt("result = %1", result));
    }
    else
    {
        error(xppCompiler.errorText());
    }
}

这将导致信息日志中出现以下错误

*** Error: 82, The operand is not compatible with the type of the function.