EnableArithmeticErrors: Boolean;
The EnableArithmeticErrors property determines whether the OnError event occurs on error occurrence in arithmetic operations during calculation of modeling problem.
Available values:
True. The OnError event occurs on error occurrence in arithmetic operations.
False. Default. The OnError event does not occur.
The OnError event handles errors on division by zero.
Executing the example requires that the repository contains a modeling container with the CONTAINER identifier. The modeling container must contain a modeling problem with the CONTAINER_TASK identifier.
Add links to the Metabase and Ms system assemblies.
Public Class MCallback: ProblemCalculationCallback
// Describe the OnError event
Public Sub OnError(Message: String);
Begin
// Display information about errors in the console
Debug.WriteLine("Error: " + Message);
End Sub OnError;
End Class MCallback;
Sub main;
Var
Mb: IMetabase;
MbDes: IMetabaseObjectDescriptor;
Problem: IMsProblem;
Calc: IMsProblemCalculation;
CallBack: MCallBack;
CalcSet: IMsProblemCalculationSettings;
Begin
// Get repository
Mb := MetabaseClass.Active;
// Get modeling problem
MbDes := Mb.ItemByIdNamespace("CONTAINER_TASK", Mb.GetObjectKeyById("CONTAINER"));
Problem := MbDes.Edit As IMsProblem;
// Set up problem calculation parameters
CalcSet := Problem.CreateCalculationSettings;
// Disable breaking problem calculation on error occurrence
CalcSet.BreakOnError := False;
// Create an object for problem calculation
Calc := Problem.Calculate(CalcSet);
// Create an object for event handling
CallBack := New MCallback.Create;
Calc.Callback := CallBack;
// Activate the OnError event operation on error occurrence in arithmetic operations
Calc.EnableArithmeticErrors := True;
// Start problem calculation
Calc.Run;
End Sub main;
After executing the example the modeling problem will be calculated. If an error occurred on calculation in arithmetic operations, the console displays the corresponding message.
See also: