Opening Problem with Parameters

Each metamodel can contain different number of parameters that can be used to manage metamodel calculation, can be used in formulas and for some other purposes. The parameters collection is described by the IMsModelParams interface, but when a problem is opened using the Open/OpenWithParam method, the collection of parameters values can be sent to the metamodel that is described by the IMetabaseObjectParamValues interface. To do this, parameters should be created beforehand in metamodel or problem metadata, and it is available to set up management between parameters. The example of given in description of the IMsModelParam.ObjectParam property.

This example describes getting of metamodel parameters, setting their values and further problem opening with parameters. Executing the example requires a modeling container with the CONT_MODEL identifier. A problem with the PROBLEM identifier is created in the container. The metamodel and the problem contain parameters with the PARAM_INT and PARAM_STR identifiers.

Sub UserProc;
Var
    Mb: IMetabase;
    Problem: IMsProblem;
    pDesc: IMetabaseObjectDescriptor;
    pParamValues: IMetabaseObjectParamValues;
    pCalcSett: IMsProblemCalculationSettings;
    pCalc: IMsProblemCalculation;
Begin
    Mb := MetabaseClass.Active;
    pDesc := Mb.ItemByIdNamespace(
"PROBLEM", Mb.GetObjectKeyById("CONT_MODEL"));
    
//Metamodel parameters
    pParamValues := ((pDesc.EditTemporary As IMsProblem).MetaModel As IMetabaseObject).ParamValues;
    
// Set parameters values
    pParamValues.FindById("PARAM_INT").Value := 100;
    pParamValues.FindById(
"PARAM_STR").Value := "X";
    
//Open problem with parameters
    Problem := pDesc.Open(pParamValues) As IMsProblem;
    
//Calculate problem
    pCalcSett := problem.CreateCalculationSettings;
    pCalc := problem.Calculate(pCalcSett);
    pCalc.Run;
End Sub UserProc;

After executing the example, the metamodel parameters collection is obtained, values are set for parameters. The problem is opened with parameters, parameters values are sent to the metamodel. After this the problem is calculated.

See also:

Examples