IDefCalculationAlgorithmsCollection.Add

Syntax

Add(objectKey: Integer; type: CalcType): IDefCalculationAlgorithm;

Parameters

objectKey. calculation algorithm key in the repository.

type. The calculation algorithm use option in table area.

Description

The Add method add calculation algorithm for use in table area.

Example

Executing the example requires that the repository contains a data entry form, for which the specified macro is set as an executable method for a custom button. Three calculation algorithms with the ALGO_CALC, ALGO_CONTROL and ALGO_END identifiers must be also created in repository. In ALGO_CALC there is calculation block with configured formulas. In ALGO_CONTROL control block is set up. ALGO_END can execute any operations. Table area is created in data entry form. The parameter with the P_CALENDAR identifier is also created and set up for data entry form. Algorithm with calculation block has a parameters which settings matches with settings of data entry form settings. It is also supposed to have additional data entry form with the 11403 key.

Add links to the Drawing, Metabase, Report, Tab system assemblies. Add links to the assemblies required for working with data entry forms.

Public Sub AddAlgorithm(Report: IPrxReport);
Var
    Mb: IMetabase;
    
//Sheet: IPrxSheet;
    DEForm: IDataEntryForm;
    TArea: IDefTableArea;
    Algs: IDefCalculationAlgorithmsCollection;
    Algo: IDefCalculationAlgorithm;
Begin
    Mb := MetabaseClass.Active;
    
// Current data entry form instance    
    DEForm := New DataEntryForm.CreateByReport(report);
    
// Get table area
    TArea := DEForm.inpuTAreas.Item(0As IDefTableArea;
    DEForm.Parameters.Item(
0);
    TArea.UpdateAfterSave := 
True;
    
// Calculation algorithms
    Algs := TArea.CalculationAlgorithms;
    
// Add calculation algorithms for changing
    Algo := Algs.Add(Mb.GetObjectKeyById("ALGO_CALC"), CalcType.CalcAfterEdit);
    ConfigureAlgo(Algo);
    Algo := Algs.Add(Mb.GetObjectKeyById(
"ALGO_CONTROL"), CalcType.CalcAfterEdit);
    ConfigureAlgo(Algo);
    
// Add calculation algorithm for saving
    Algs.Add(Mb.GetObjectKeyById("ALGO_END"), CalcType.CalcAfterSave);
    
// View information about obtained collection of calculation algorithms
    ShowAlgsInfo(Algs);
    
// Apply changes to data entry form
    DEForm.inpuTAreas.ApplyAreaToReport(TArea.id);
    DEForm._Dispose;
End Sub AddAlgorithm;

Sub ConfigureAlgo(Algo: IDefCalculationAlgorithm);
Var
    Style: ITabCellStyle;
    Params: IDefCalculationAlgorithmParametersCollection;
    Param: IDefCalculationAlgorithmParameter;
    MapInfo: IDefCalculationAlgorithmMapInfo;
    MapParamInf: IDefCalclulationAlgorithmMapParamInfo;
Begin
    
If Algo.HasCalcBlock Then
        Algo.SaveDataOption := 
True;
        Algo.ExtendLoadSelection := 
True;
        Algo.CalcPeriod := CalcPeriodMode.AllSelectionFromAlgorithm;
        
// Bind calculation algorithm parameters
        Params := Algo.Parameters;
        Param := Params.Item(
0);
        Param.Type := CalcParamType.param;
        Param.SelectionMode := CalcParamSchema.selected;
        Param.FormParameterId := 
"P_CALENDAR";
        
// Bind data entry form to algorithm to drill down formulas
        MapInfo := Algo.MapInfo.Item(0);
        MapInfo.FormKey := 
11403;
        MapParamInf := MapInfo.MapParameters.Item(
0);
        MapParamInf.ThisFormParameterId := 
"P_CALENDAR";
    
Elseif Algo.HasValidationBlock Then
        Style := 
New TabCellStyle.Create;
        Style.Font.Bold := TriState.OnOption;
        Style.Font.Color := GxColor.FromKnownColor(GxKnownColor.Red);
        Algo.ControlStyle := Style;
        Algo.BlockSaveData := 
True;
    
End If;
End Sub ConfigureAlgo;

Sub ShowAlgsInfo(Algs: IDefCalculationAlgorithmsCollection);
Var
    Algo: IDefCalculationAlgorithm;
    i, c: Integer;
Begin
    c := Algs.Count;
    
For i := 0 To c - 1 Do
        Algo := Algs.Item(i);
        Debug.WriteLine(Algo.Name + 
"(Key: " + Algo.Key.ToString + ". Unique identifier: " + Algo.Unical.ToString + ')');
        Debug.Indent;
        Debug.WriteLine(
"Use option: " + (Algo.Type = CalcType.CalcAfterEdit ? "For change" : "For save"));
        Debug.WriteLine(
"Calculation block: " + Algo.HasCalcBlock.ToString + "; Control block: " + Algo.HasValidationBlock.ToString);
        Debug.Unindent;
    
End For;
End Sub ShowAlgsInfo;

On executing macro for table area, three calculation algorithms are added and set up. Work settings and parameters binding will be set for algorithms. After this, information about calculation algorithms will be displayed in the development environment console.

See also:

IDefCalculationAlgorithmsCollection