IMatrixEx.CreateWritableProxyO

Syntax

CreateWritableProxyO(Options: Integer): IMatrix;

CreateWritableProxyO(Options: integer): Prognoz.Platform.Interop.Matrix.IMatrix;

Parameters

Options. Parameters of creating a proxy object of data matrix.

Description

The CreateWritableProxyO method creates a proxy object of data matrix.

Comments

Use the 0 value in the Options parameter. Created proxy object provides separate work with initial and modified matrix data. To control data, cast the CreateWritableProxyO method result to the IMatrixWritableProxy interface.

Example

Executing the example requires that repository contains a cube with the CUBE identifier.

Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    DefDest: ICubeInstanceDestination;
    SelSet: IDimSelectionSet;
    i: integer;
    DestExec: ICubeInstanceDestinationExecutor;
    Proxy: IMatrix;
    Wp: IMatrixWritableProxy;
    Iter: IMatrixIterator;
    Mc: IMatrixCoord;
Begin
    MB := MetabaseClass.Active;
    CubeInst := MB.ItemById(
"CUBE").Open(NullAs ICubeInstance;
    DefDest := CubeInst.Destinations.DefaultDestination;
    SelSet := DefDest.CreateDimSelectionSet;
    
For i := 0 To SelSet.Count - 1 Do
        SelSet.Item(i).SelectAll;
    
End For;
    DestExec := DefDest.CreateExecutorO(CubeInstanceDestinationExecutorOptions.MatrixProxy);
    DestExec.PrepareExecute(SelSet);
    DestExec.PerformExecute(
False);
    Proxy := (DestExec.Matrix 
As IMatrixEx).CreateWritableProxyO(0);
    Wp := Proxy 
As IMatrixWritableProxy;
    Debug.WriteLine(
"---------------Initial values in matrix and proxy matrix-------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    Debug.WriteLine(
"---------------Add a new value-----------------------------------------");
    Mc := Proxy.CreateCoord;
    Iter := Proxy.CreateIterator;
    Iter.Move(IteratorDirection.First);
    Iter.PutCurrentPos(Mc);
    
For i := 0 To Mc.Count - 1 Do
        Mc.Item(i) := Mc.Item(i) + 
1
    
End For;
    
//Check whether coordinate exists
    Iter.Goto(Mc);
    
If Iter.Valid Then
        Debug.WriteLine(
"Coordinate already exists.");
    
Else
        Debug.WriteLine(
"Coordinate does not exist.");
    
End If;
    
//Move to coordinate and set value. If coordinate does not exist, then matrix will be expanded
    Iter.PutCoord(Mc);
    Iter.Value := 
100500;
    Debug.WriteLine(
"New value = " + Iter.Value);
    Debug.WriteLine(
"---------------Changed/added values------------------------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    Debug.WriteLine(
"---------------after ApplyChanges-------------------------------------------------");
    Wp.ApplyChanges;
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    Debug.WriteLine(
"---------------Repeated value changing by coordinate-------------------------");
    Iter.PutCoord(Mc);
    Iter.Value := -Iter.Value;
    Debug.WriteLine(
"New value = " + Iter.Value);
    Debug.WriteLine(
"---------------Changed/added values------------------------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    Debug.WriteLine(
"---------------after RevertChanges------------------------------------------------");
    Wp.RevertChanges;
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
End Sub UserProc;

Sub ShowMatrix(MatrixName: String; Matr: IMatrix);
Var
    Iter: IMatrixIterator;
Begin
    Debug.Write(MatrixName + 
" : ");
    
If Matr.Count <> 0 Then
        Iter := Matr.CreateIterator;
        Iter.Move(IteratorDirection.First);
        
While Iter.Valid Do
            Debug.Write(Iter.Value + 
" ");
            Iter.Move(IteratorDirection.Next);
        
End While;
        Debug.WriteLine(
"");
    
Else
        Debug.WriteLine(
"Empty");
    
End If;
End Sub ShowMatrix;

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    CubeInst: ICubeInstance;
    DefDest: ICubeInstanceDestination;
    SelSet: IDimSelectionSet;
    i: integer;
    DestExec: ICubeInstanceDestinationExecutor;
    Proxy: IMatrix;
    Wp: IMatrixWritableProxy;
    Iter: IMatrixIterator;
    Mc: IMatrixCoord;
    d: double;
Begin
    MB := Params.Metabase;
    CubeInst := MB.ItemById[
"CUBE"].Open(NullAs ICubeInstance;
    DefDest := CubeInst.Destinations.DefaultDestination;
    SelSet := DefDest.CreateDimSelectionSet();
    
For i := 0 To SelSet.Count - 1 Do
        SelSet.Item[i].SelectAll();
    
End For;
    DestExec := DefDest.CreateExecutorO(CubeInstanceDestinationExecutorOptions.cideoMatrixProxy 
As Integer);
    DestExec.PrepareExecute(SelSet);
    DestExec.PerformExecute(
False);
    Proxy := (DestExec.Matrix 
As IMatrixEx).CreateWritableProxyO(0);
    Wp := Proxy 
As IMatrixWritableProxy;
    System.Diagnostics.Debug.WriteLine(
"---------------Initial values in matrix and proxy matrix-------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    System.Diagnostics.Debug.WriteLine(
"---------------Add a new value-----------------------------------------");
    Mc := Proxy.CreateCoord();
    Iter := Proxy.CreateIterator();
    Iter.Move(IteratorDirection.itdFirst);
    Iter.PutCurrentPos(Mc);
    
For i := 0 To Mc.Count - 1 Do
        Mc.Item[i] := Mc.Item[i] + 
1
    
End For;
    
//Check whether coordinate exists
    Iter.Goto(Mc);
    
If Iter.Valid Then
        System.Diagnostics.Debug.WriteLine(
"Coordinate already exists.");
    
Else
        System.Diagnostics.Debug.WriteLine(
"Coordinate does not exist.");
    
End If;
    
//Move to coordinate and set value. If coordinate does not exist, then matrix will be expanded
    Iter.PutCoord(Mc);
    Iter.Value := 
100500;
    System.Diagnostics.Debug.WriteLine(
"New value = " + Iter.Value);
    System.Diagnostics.Debug.WriteLine(
"---------------Changed/added values------------------------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    System.Diagnostics.Debug.WriteLine(
"---------------after ApplyChanges-------------------------------------------------");
    Wp.ApplyChanges();
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    System.Diagnostics.Debug.WriteLine(
"---------------Repeated value changing by coordinate-------------------------");
    Iter.PutCoord(Mc);
    d := double.Parse(Iter.Value.ToString());
    Iter.Value := -d;
    System.Diagnostics.Debug.WriteLine(
"New value = " + Iter.Value);
    System.Diagnostics.Debug.WriteLine(
"---------------Changed/added values------------------------------------");
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
    System.Diagnostics.Debug.WriteLine(
"---------------after RevertChanges------------------------------------------------");
    Wp.RevertChanges();
        ShowMatrix(
"Proxy", Proxy);
        ShowMatrix(
"BaseMatrix", Wp.BaseMatrix);
        ShowMatrix(
"ChangeMatrix", Wp.ChangeMatrix);
End Sub;

Shared Sub ShowMatrix(MatrixName: String; Matr: IMatrix);
Var
    Iter: IMatrixIterator;
Begin
    System.Diagnostics.Debug.Write(MatrixName + 
" : ");
    
If Matr.Count <> 0 Then
        Iter := Matr.CreateIterator();
        Iter.Move(IteratorDirection.itdFirst);
        
While Iter.Valid Do
            System.Diagnostics.Debug.Write(Iter.Value + 
" ");
            Iter.Move(IteratorDirection.itdNext);
        
End While;
        System.Diagnostics.Debug.WriteLine(
"");
    
Else
        System.Diagnostics.Debug.WriteLine(
"Empty");
    
End If;
End Sub;

On executing the example, a new value is added to matrix and then it is changed. The development environment console displays data of initial matrix, proxy object matrix and matrix where changed values of proxy object during work process are stored.

See also:

IMatrixEx