PV ADD DYNAMIC FIELDS
version 6.8
PV ADD DYNAMIC FIELDS (area; master; tables; fields; methods)
Parameter | Type | Description | |
area | Longint | 4D View area | |
master | Integer | Master table number | |
tables | Integer Array | Table numbers array | |
fields | Integer Array | Field numbers array | |
methods | String Array | Callback methods array |
Description
The PV ADD DYNAMIC FIELDS command adds, in area, a block of rows corresponding to the values of fields defined by tables and fields for the current selection of the table defined by master, starting from the A1 cell. If dynamic columns have already been defined in area, the new block will be inserted starting from row 1 of the first available column. Values of fields can be modified directly from 4D View using the corresponding cells.
The result is always vertically present (as columns as well as tables,fields and methods array elements).
Note: If a dynamic arrays area was already inserted in the 4D View area using the PV ADD DYNAMIC ARRAYS command, it is deleted and replaced by the dynamic fields.
For any column, the operation can concern an array related to a master table by a relation. The latter must be an automatic type and go from the master array to the array of the field to display. In the traditional example of invoices and invoice rows, you can recuperate and modify the content of a field of the rows array, but also of the invoice table compared to a selection from the invoice rows array (master table).
Each callback method receives six parameters:
$1: Area
$2: Column number
$3: Array type
$4: Pointer to this array
$5: Number of the first row to (re)draw
$6: Number of rows to (re)draw in the area
Note: If you intend to compile your database, you must declare these parameters, even if you do not use them all.
$5 and $6: When the user scrolls the rows (records) in area, only new displayed rows are (re)drawn. $5 and $6 parameters allow you to know which rows are concerned.
The developer should fill in the callback methods array. 4D View will then use that array to fill in the calculated column. There is no returned value ($0).
PV ADD DYNAMIC FIELDS keeps a dynamic link with fields passed as parameters. As a result, modifications of values executed in the 4D View area are reflected in field(s) and vice-versa.
Notes:
• 4D methods and field values must be defined in the same process as the 4D View area.
• Dynamic data update is not available between the records displayed in 4D forms and 4D View external windows. To reflect in a 4D View window a modification carried out in the 4D record, you need to redraw the window using the PV REDRAW command (modifications executed through 4D commands are automatically reflected into 4D View areas).
Example
This example illustrates an enterable table included in an input form (with 4D View, this is rather easy). We will then modify fields in the contact table related to the current client, with their functions (linked table) and initials of each contact (calculated column).
ARRAY INTEGER($TablesArray;4) `Table numbers
ARRAY INTEGER($FieldsArray;4) `Field numbers
ARRAY STRING(30;$MethodsArray;4) `Callback method names
`Column 1: contact name
$TablesArray{1}:=Table(->[Contacts])
$FieldsArray{1}:=Field(->[Contacts]ContactName)
$MethodsArray{1}:=""
`Column 2: contact first name
$TablesArray{2}:=Table(->[Contacts])
$FieldsArray{2}:=Field(->[Contacts]ContactFirstname)
$MethodsArray{2}:=""
`Column 3: contact title (linked table)
$TablesArray{3}:=Table(->[Titles])
$FieldsArray{3}:=Field(->[Titles]Label)
$MethodsArray{3}:=""
`Column 4: order number/ total (calculated column)
$TablesArray{4}:=0
$FieldsArray{4}:=Is text `Result
$MethodsArray{4}:="CallMethod"
RELATE MANY([Clients]Code) `Get contacts
PV ADD DYNAMIC FIELDS (Area;Table(->[Contacts]);$TablesArray;$FieldsArray;$MethodsArray)
The code for the CallMethod project method is as follows:
C_LONGINT($1) `4D View area
C_LONGINT($2) `Column number
C_LONGINT($3) `Type of array
C_POINTER($4) `Pointer to this array
C_LONGINT($5) `First row of the dynamic area
C_LONGINT($6) `Number of lines that can be displayed in the area
GOTO SELECTED RECORD([Contacts];$5)
For($i;1;$6)
$4->{$i}:=Substring([Contacts]ContactFirstname;1;1)+Substring([Contacts]ContactName;1;1)
NEXT RECORD([Contacts])
End for
See Also
PV ADD DYNAMIC ARRAYS, PV CLEAR DYNAMIC COLUMNS, PV FIELD TO CELLS, PV SET CELL FIELD.