haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Quintiq file version 2.0
#parent: #root
Method ComponentMDS_SelectInstance (
  internal[GUIComponent] component,
  Scenario scenario
) id:Method_ApplicationLibMacroPlanner_ComponentMDS_SelectInstance
{
  #keys: '[144528.3.491344179]'
  Body:
  [*
    // Select MDS instance for a component
    if( not isnull( scenario ) )
    {
      loop := true;
      p := Progress::Level( 'Loading scenario...', 10 );
      
      // changed the operation in "p.Current() < p.Maximum()" from <= to < as p.Maximum will never be reached
      // causing an infinite loop when a dataset is no longer available
      while( loop and p.Current() < p.Maximum() )
      {
        componentmds := ComponentMDS::CreateForLoadedMDSsOnly( component );
        mdsinstance := select( componentmds, ComponentMDSKinds.ComponentMDSInstances, m, m.MDSID().MDSKey() = scenario.DatasetMDSID() );
      
        if( not isnull( mdsinstance ) )
        {
          mdsinstance.ComponentMDSKind().SelectInstance( mdsinstance );
          componentmds.Apply();
          loop := false;
        }
        p.Increment();
      }
    }
  *]
}