FindByKey(InrernalKey: Integer): IMsScenario;
FindByKey(InrernalKey: uinteger): Prognoz.Platform.Interop.Ms.IMsScenario;
InrernalKey. Internal key of the modelling scenario.
The FindByInternalKey method searches for the modelling scenario by the internal key.
To get the internal key of the modelling scenario, use the IMsScenario.InternalKey property.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier containing a modeling problem with the PROBLEM identifier. The modeling container must contain several modelling scenarios.
Add links to the Metabase, Ms system assemblies.
Sub FindByInternalKey;
Var
MB: IMetabase;
MsObj: IMetabaseObject;
MObj: IMetabaseObject;
Ms: IMsModelSpace;
Problem: IMsProblem;
ScenTree: IMsScenarioTreeEntries;
MsScen, PoblemScen: IMsScenario;
IntKey: Integer;
ProbScen: IMsProblemScenarios;
Begin
MB := MetabaseClass.Active;
// Get modeling container
MsObj := MB.ItemById("MODEL_SPACE").Bind;
Ms := MsObj As IMsModelSpace;
// Get modeling problem
MObj := MB.ItemByIdNamespace("PROBLEM", MsObj.Key).Edit;
Problem := MObj As IMsProblem;
// Get the first scenario in the modeling container
ScenTree := Ms.ScenarioTree;
MsScen := (ScenTree.Item(0) As IMsScenarioTreeElement).Scenario;
// Get the internal key of the modelling scenario
IntKey := MsScen.InternalKey;
// Get modeling problem scenarios
ProbScen := Problem.Scenarios;
// Search for the first scenario of the container
// modelling in scenarios of the modelling problem
PoblemScen := ProbScen.FindByInternalKey(IntKey);
// If the scenario is found, remove it from the modeling problem
If PoblemScen <> Null Then
ProbScen.RemoveByInternalKey(IntKey);
End If;
// Save modeling problem
MObj.Save;
End Sub FindByInternalKey;
Example execution result: the first scenario of the modeling container will be removed from the collection of scenarios of the PROBLEM modeling problem if this scenario is contained in the collection.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
MsObj: IMetabaseObject;
MObj: IMetabaseObject;
Ms: IMsModelSpace;
Problem: IMsProblem;
ScenTree: IMsScenarioTreeEntries;
MsScen, PoblemScen: IMsScenario;
IntKey: uinteger;
ProbScen: IMsProblemScenarios;
Begin
MB := Params.Metabase;
// Get modeling container
MsObj := MB.ItemById["MODEL_SPACE"].Bind();
Ms := MsObj As IMsModelSpace;
// Get modeling problem
MObj := MB.ItemByIdNamespace["PROBLEM", MsObj.Key].Edit();
Problem := MObj As IMsProblem;
// Get the first scenario in the modeling container
ScenTree := Ms.ScenarioTree;
MsScen := (ScenTree.Item[0] As IMsScenarioTreeElement).Scenario;
// Get the internal key of the modelling scenario
IntKey := MsScen.InternalKey;
// Get modeling problem scenarios
ProbScen := Problem.Scenarios;
// Search for the first scenario of the container
// modelling in scenarios of the modelling problem
PoblemScen := ProbScen.FindByInternalKey(IntKey);
// If the scenario is found, remove it from the modeling problem
If PoblemScen <> Null Then
ProbScen.RemoveByInternalKey(IntKey);
End If;
// Save modeling problem
MObj.Save();
End Sub;
See also: