Ms > Examples > History of Problem Calculation: Report by 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.
Add links to the Cubes, Express, Forms, Matrix, Metabase, Ms system assemblies.
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;
//Create a new empty 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;
//The first history of problem calculation
HistObj := MDesc.Children.Item(0);
Hist := HistObj.Bind As IMsCalculationHistory;
HistChild := HistObj.Children;
//Search for 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 all variables included in problem
VarList := Problem.VariableStubs(MsVariableKind.All);
DS := (Expr As IEaxDataAreaSource).VirtualSources;
DS.BeginUpdate;
//Load variable data saved in history to 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;
//Load report to UiErAnalyzer to view
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. This report is loaded to UiErAnalyzer1 and is displayed in all the components connected to it.
See also: