Callback: IMsProblemCalculationCallback;
The Callback property determines the object used to handle events occurring on problem calculation.
On calculating the problem the following events are possible:
The breakpoint triggered.
Error occurred.
Calculation is finished.
Calculation is prepared.
New calculation step started.
Calculation step is executed.
Warning is occurred.
Preparing to data saving.
Saving data.
Executing the example requires a modeling container with the MODEL_SPACE identifier containing a modeling problem with the PROBLEM identifier.
Add links to the Metabase, Ms system assemblies. Also, the example uses the MCallback class, the description of which is given in IMsProblemCalculationCallback.OnWarning.
Sub ProblemCalc;
Var
mb: IMetabase;
MsKey: Integer;
Problem: IMsProblem;
Calculation: IMsProblemCalculation;
CallBack: MCallback;
CalcSettings: IMsProblemCalculationSettings;
Begin
mb := MetabaseClass.Active;
// Get modeling problem
MsKey := mb.GetObjectKeyById("MODEL_SPACE");
Problem := mb.ItemByIdNamespace("PROBLEM", MsKey).Bind As IMsProblem;
// Set problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings;
CalcSettings.FactIncluded := True;
CalcSettings.BreakOnError := True;
Calculation := Problem.Calculate(CalcSettings);
// Set event handler
CallBack := New MCallback.Create;
Calculation.Callback := CallBack;
// Perform calculation
Calculation.Run;
End Sub ProblemCalc;
After executing the example the problem is calculated. If there is an error, the calculation is stopped. The handler of the events occurring on problem calculation is the MCallback class.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Metabase;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
Problem: IMsProblem;
Calculation: IMsProblemCalculation;
CallBack: MCallback;
CalcSettings: IMsProblemCalculationSettings;
Begin
mb := Params.Metabase;
// Get modeling problem
MsKey := mb.GetObjectKeyById("MODEL_SPACE");
Problem := mb.ItemByIdNamespace["PROBLEM", MsKey].Bind() As IMsProblem;
// Set problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings();
CalcSettings.FactIncluded := True;
CalcSettings.BreakOnError := True;
Calculation := Problem.Calculate(CalcSettings);
// Set event handler
CallBack := New MCallback.Create();
Calculation.Callback := CallBack;
// Perform calculation
Calculation.Run();
End Sub;
See also: