5

Please add new built-in type called Delegate (or something similar) that could be used to save procedure invocation including parameter values and actually invoke procedure elsewhere.


The Delegate instance would have only a single method Invoke() that does not take parameters or return a value.


The Delegate instance would be created by using delegate keyword on a procedure call. Only procedures that do not return values should be accepted. Procedures that uses var parameters should be accepted, but var parameters will not be used to return values back to the caller - needed to pass table filters or temporary table.


The Delegate should function as if it was a codeunit that saved procedure parameter values in globals and have a procedure that calls the original procedure with those globals as parameters.


The Delegate type would reduce the need for complicated and error prone error handling and logging code used in complex integrations - you only need to pass the worker procedure and parameters - calling procedure and handling errors and logging can be done in one place.


Example 1:

Delegate := delegate Message('123');

Sleep(60 * 1000);

Delegate.Invoke(); // shows message 123


Example 2:

Delegate := delegate Message('%1', CurrentDateTime);

Sleep(60 * 1000);

Delegate.Invoke(); // shows time 1 minute ago - only parameter values passed to Message should be saved


Example 3:

Item."No." := 'A';

Delegate := delegate Message('%1', Item);

Item."No." := 'B';

Delegate.Invoke(); // shows 'A ...' - only Item field values are saved in the delegate


Example 4:

Item.SetRange("No.", 'A');

Delegate := delegate Item.GetFilter("No."); // compiler error - functions with return values are not allowed


Example 5:

Delegate := delegate Item.SetFilter("No.", '<>%1', ''); // compiler error - delegate must be in from of procedure name in procedure call


Example 6:

delegate DoSomething(); // compiler error - Delegate must be assigned to variable or parameter


Example 7:

Item.SetFilter("No.", '<>%1', '');

Delegate := delegate MyProcedure(Item); // MyProcedure uses var parameter and shows Item filters

Delegate.Invoke(); // shows item field "No." filter


Example 8:

CodeunitRunner.RunWithErrorLogging(delegate WorkerProcedure(MyParameter1, MyParameter2));

Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team

Comments

E

Idea post in yammer: https://www.yammer.com/dynamicsnavdev/threads/3013695639470080

Category: Development