Measure management
A measure can be created based on either a slice field or a FastScript script.
function AddMeasure(ASliceField: TfcxSliceField; AName, ACaption: TfcxString; AAgrFunc: TfcxAgrFunc): Integer;
Adds a measure based on ASliceField with aggregate function AAgrFunc. Returns the position of the measure in the container.
function AddCalcMeasure(AName, ACaption: TfcxString; AAgrFunc: TfcxAgrFunc; AScriptFunctionName: String; AScriptFunctionCode: TfcxString): Integer;
Adds a calculated measure based on script function AScriptFunctionName with aggregate function AAgrFunc. AScriptFunctionCode - the function's code. Returns the position of the measure in the container.
function AddMeasure(AField: TfcxMeasureField): Integer;
Adds specified measure AField. Returns the position of the measure in the container.
procedure InsertMeasure(ASliceField: TfcxSliceField; AName, ACaption: TfcxString; AAgrFunc: TfcxAgrFunc; AIndex: TfcxSmallCount);
Inserts a measure based on ASliceField with aggregate function AAgrFunc in the specified container position.
procedure InsertCalcMeasure(AName, ACaption: TfcxString; AAgrFunc: TfcxAgrFunc; AScriptFunctionName: String; AScriptFunctionCode: TfcxString; AIndex: TfcxSmallCount);
Inserts a calculated measure based on script function AScriptFunctionName with aggregate function AAgrFunc in the specified container position. AScriptFunctionCode - the function's code.
procedure InsertMeasure(AField: TfcxMeasureField; AIndex: TfcxSmallCount);
Inserts specified measure AField in the specified container position.
procedure DeleteMeasure(AMeasureIndex: TfcxSmallCount; ADoStopChange: Boolean = False);
Deletes the measure with the specified index.
MeasuresContainer methods and properties allow access to and editing of measures.
Measures can be hidden. Hidden measures are also calculated.
function MoveMeasure(AFromIndex, AToIndex: TfcxSmallCount): boolean;
Moves measure within the container.
property Measures[AIndex: TfcxSmallCount]: TfcxMeasureField;
Measure access property.
TfcxMeasureField properties and methods allow editing of measure properties:
property Visible: Boolean;
Measure visibility.
property DisplayAs: TfcxDisplayAs;
Display style.
All operations changing the slice structure are best placed between BeginUpdate and EndUpdate calls. This prevents unnecessary recalculations and rebuilds on each change.
Code examples:
// begin structure change - suspend recalculations on slice
fcxSlice1.BeginUpdate;
// add a measure based on slice field indexed 3 and aggregate function af_Sum
fcxSlice1.MeasuresContainer.AddMeasure(fcxSlice1.SliceField[3],'Sum1', 'Income', af_Sum);
// add a calculated measure, which calculates half of Income
fcxSlice1.MeasuresContainer.AddCalcMeasure('Calc1', 'Half of Income', af_Formula, 'CalcScript1', 'Result := measures[''Sum1''].currentvalue / 2');
// move the measure indexed 1 to position 0
fcxSlice1.MeasuresContainer.MoveMeasure(1, 0)
// hide the measure indexed 1
fcxSlice1.MeasuresContainer.Measures[1].Visible := False;
// finish structure change, start recalculations on slice
fcxSlice1.EndUpdate;