Considerations on using structures as parameters of procedures and functions





Main article: Procedure and function parameters 

When dealing with procedures and functions (referred to further as functions) that have parameters of the Structure type, we recommend following the approach to development as described below.

1. In addition to the function that implements the application functionality (the function that is called), define a constructor function for creating a structure (the constructor of parameters). In this case, the constructor function does not accept any parameters and only returns a blank structure with properties. The code that calls the function initializes the structure with specific values and then passes it to the function being called.

Sample code that calls the function:

Procedure OnItemChangeServer(CurrentRowID)

// Getting new parameter structure.
PriceFillingParameters = PricingClientServer.TSRowPriceFillingParameters(); 

// Filling parameters.
PriceFillingParameters.Date = Object.Date;
PriceFillingParameters.Currency = Object.Currency;

CurrentRow = Object.Items.FindByID(CurrentRowID);

// Passing parameter structure to the applied function.
PricingServer.FillPricesInTSRow(CurrentRow, PriceFillingParameters);

Example of parameter constructor function in PricingClientServer module:

Function TSRowPriceFillingParameters() Export
 
 PriceFillingParameters = New Structure;
 PriceFillingParameters.Insert("Date");
 PriceFillingParameters.Insert("Currency");
 PriceFillingParameters.Insert("RecalculateAmount", True);
 PriceFillingParameters.Insert("RequiredParameters","Date,Currency"); // required parameters that must be filled
 Return PriceFillingParameters;
 
EndFunction

The names of structure properties correspond to the parameters of the called function. Note that any parameters with default values should be explicitly initialized in this structure.

2. Do not add any other properties to the parameter structure in the calling code. In order to avoid ambiguity and hidden errors, all valid parameters of the called function should be explicitly defined in the parameter constructor function.


Comments
0
Add comment