Brad
Brad

Reputation: 1369

DictTable CallObject

I am using the following code to dynamically execute calls to a table method that may or may not be present.

However, it always returns Error executing code: myTableName table does not have method 'myUpdateMethod'.

    Dicttable         dictTable;
    Common            common;
    ExecutePermission perm;

    perm = new ExecutePermission();
    dictTable= new DictTable(tableName2Id('myTableName'));
    if (dictTable != null)
    {
        common = dictTable.makeRecord();

        // Grants permission to execute the
        // DictTable.callObject method. DictTable.callObject runs
        // under code access security.
        perm.assert();
        dictTable.callObject('myUpdateMethod', common);
    }

    // Close the code access permission scope.
    CodeAccessPermission::revertAssert();

These objects are in different models, but just for kicks I tried making a reference between the two models to see if it made a difference. It did not fix the issue.

Thanks

Upvotes: 1

Views: 1244

Answers (1)

Brad
Brad

Reputation: 1369

Changed the method being called from static to non-static.

Started working, then found the callStatic() equivalent.

Here is the code I ended up using for the non-static method, which has no params.

    Dicttable         dictTable;
    Common            common;
    ExecutePermission perm;

    perm = new ExecutePermission();
    dictTable= new DictTable(tableName2Id('MyTableName'));
    if (dictTable != null)
    {
        common = dictTable.makeRecord();
        // Grants permissions
        perm.assert();
        if (dictTable.doesMethodExist('myMethodName'))
        {
            dictTable.callObject('myMethodName', common);
        }
    }

    // Close the code access permission scope.
    CodeAccessPermission::revertAssert();

Upvotes: 1

Related Questions