History of Problem Calculation: Report by the Variables

Executing the example requires a form with a button named Button1, the UiErAnalyzer component named UiErAnalyzer and any components that display the express report data loaded to UiErAnalyzer. The KONT_MODEL modeling container in the repository contains the PROBLEM_1 problem. The given problem has calculation history.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);

Var

MB: IMetabase;

CrInfo: IMetabaseObjectCreateInfo;

Expr: IEaxAnalyzer;

MDesc, HistObj: IMetabaseObjectDescriptor;

HistChild: IMetabaseObjectDescriptors;

Hist: IMsCalculationHistory;

DS: IEaxDataSources;

Problem: IMsProblem;

VarList: IVariableStubList;

VarStub: IVariableStub;

Inst: ICubeInstance;

Begin

MB := MetabaseClass.Active;

//Creating new blank express report

CrInfo := MB.CreateCreateInfo;

CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_EXPRESSREPORT;

CrInfo.Id := MB.GenerateId("NewExpress");

CrInfo.Name := CrInfo.Id;

CrInfo.Parent := MB.Root;

Expr := MB.CreateObject(CrInfo).Edit As IEaxAnalyzer;

//modeling problem

MDesc := MB.ItemByIdNamespace("PROBLEM_1", MB.ItemById("KONT_MODEL").Key).Bind;

//First problem calculation history

HistObj := MDesc.Children.Item(0);

Hist := HistObj.Bind As IMsCalculationHistory;

HistChild := HistObj.Children;

//Search the problem saved in history

For Each MDesc In HistChild Do

If MDesc.ClassId = MetabaseObjectClass.KE_CLASS_MSPROBLEM Then

Break

End If;

End For;

Problem := MDesc.Bind As IMsProblem;

//Get list of the variables included to the problem

VarList := Problem.VariableStubs(MsVariableKind.All);

DS := Expr.DataSources;

DS.BeginUpdate;

//Loading saved in history variables values to the report

For Each VarStub In VarList Do

Inst := ((VarStub As IMsVariable).Cube As IMetabaseObject).Open(Null) As ICubeInstance;

DS.Add(Inst.Destinations.DefaultDestination As IMatrixDataSource);

End For;

DS.EndUpdate;

//Loading of the report to the UiErAnalyzer for previewing

UiErAnalyzer1.ErAnalyzer := Expr;

UiErAnalyzer1.Active := True;

End Sub Button1OnClick;

After executing the example a blank express report is created on pressing the button. All the variables data used by the problem and saved to the first report history is loaded to this report. The given report is loaded to UiErAnalyzer1 and displayed in all the components connected to it.

See also:

Examples