PrintList Pro columns can be calculated “on the fly” to print the results of calculations performed in a callback method.
This feature is available for both field and array printing modes.
The PL_SetFields command is used both to set fields to be printed and to set up calculated columns.
The following table shows the data types that may be printed in a calculated column in field mode:
Constant | Value |
---|---|
Is Alpha Field | 0 |
Is Real | 1 |
Is Text | 2 |
Is Picture | 3 |
Is Date | 4 |
Is Boolean | 6 |
Is Integer | 8 |
Is LongInt | 9 |
Is Time | 11 |
For example, to print a calculated column of type Real, pass Is Real (-1) in the fieldNum parameter.
The PL_SetCalcCall command is used to set up calculated columns in array mode.
To make a column calculated, create a regular array-based column and then use:
PL_SetCalcCall (area; column; methodName)
The callback parameters are expected to be declared as (area:L; column:L; type:L; ptr:W; first:L;count:L).
This callback method has the same parameters as a column callback in fields mode, but the array is fully sized (by you as developer), you have to fill the requested elements.
The type is the actual array type, not a field type (e.g. LongInt array instead of Is LongInt)
The following table shows the data types that may be printed in a calculated column in array mode:
Constant | Value |
---|---|
Real array | 14 |
Integer array | 15 |
LongInt array | 16 |
Date array | 17 |
Text array | 18 |
Picture array | 19 |
String array | 21 |
Boolean array | 22 |
In both field mode and array mode, use the PL_SetCalcCall command to set the Calculated Column Callback for a column.
In field mode, PrintList Pro will dimension the temporary array before invoking the calculated column callback. There is no need to do it in the callback itself.
In array mode, the arrays used to place the calculated values must be declared and sized just as the other displayed arrays.
The following is an example of a calculated callback method in field mode. It merely calculates an employee’s one year anniversary by adding one year to their hire date (using the 4D Add to date function).
// CalcColCallback // $1: Area reference (PrintList Pro longint reference) // $2: Column number // $3: Type of data in this column // $4: Pointer to temporary 4D array // $5: First record for which to calculate cell // $6: Number of cells to calculate in column // Declare the parameters C_LONGINT($1;$2;$3;$5;$6) // these must be declared C_POINTER($4) // this must be declared C_LONGINT ($i) ARRAY DATE($aHireDate;0) // local array can be used since we only need it here for calculation SELECTION RANGE TO ARRAY($5;$5+$6-1;[Employee]Hire Date;$aHireDate) For ($i;1;$6) $4->{$i}:= Add to date($aHireDate{$i};1;0;0) End for
The following is an example of a calculated callback method in array mode, using the same simple calculation as above, but with 4D arrays being printed.
These arrays have been initially declared and included in the PrintList Pro area with the same command (either PL_SetArraysNam or PL_AddColumn) for both non-calculated and calculated arrays:
// Declare the arrays ARRAY TEXT(aName;0) ARRAY DATE(aHireDate;0) // not printed, but needed for calculation SELECTION TO ARRAY([Employee]Name;aName;[Employee]Hire Date;aHireDate) ARRAY DATE (aAnniversary;Size of array(aName)) // this is our calculated array - must be of same size! // Arrays to print $error:= PL_AddColumn(eList;->aName;0) // no need to specify colum number $error:= PL_AddColumn(eList;->aAnniversary;0) // Set calculated callback method for column 2 PL_SetCalcCall (eList;2;”CalcColCallbackArray”)
Now we use the callback as previously to populate the array on the fly:
// CalcColCallbackArray // $1: Area reference (PrintList Pro longint reference) // $2: Column number // $3: Type of array in this column // $4: Pointer to the printed array // $5: First row for which to calculate cell // $6: Number of cells to calculate in column // Declare the parameters C_LONGINT($1;$2;$3;$5;$6) // these must be declared C_POINTER($4) // this must be declared C_LONGINT ($i) For ($i;$5;$5+$6-1) $4->{$i}:= Add to date(aHireDate{$i};1;0;0) End for
(areaRef:L; columnNumber:L; calcCallback:T)
Parameter | Type | Description |
---|---|---|
→areaRef | longint | Reference of PrintList Pro object on layout. |
→columnNumber | longint | Column number. |
→calcCallback | text | 4D method called to fill row(s) of a calculated column. |
PL_SetCalcCall is used to set a callback method for a calculated column.
columnNumber — This parameter specifies the column on which to attach the calcCallback method.
calcCallback — This method will be called whenever row(s) need to be filled in a calculated column. If this is an empty string then no method will be called.
The first two parameters ($1 and $2) passed to this callback method are areaRef and columnNumber. Therefore, if desired, the same callback can be used for more than one PrintList Pro object and for many columns in an object.
For information on how to write a calculated column callback, see the section Calculated Column Callback.
// Set calculated callback method for column 3 PL_SetCalcCall (eArea;3;”CalcColCallback”)