4D v16.3Using object arrays in columns (4D View Pro) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v16.3
Using object arrays in columns (4D View Pro)
Using object arrays in columns (4D View Pro)
List box columns can work with object arrays. Since object arrays can contain different kinds of data, this powerful feature allows you to enter and display various types of values in the rows of a single column, and use various widgets as well. For example, you could insert a text input in the first row, a check box in the second, and a drop-down list in the third. Object arrays also provide access to new kinds of widgets, such as buttons or color pickers. The following list box was designed using an object array: About 4D View Pro: The ability to use object arrays in list boxes is a "4D View Pro" function, which means that its use requires you to have a valid 4D View license. 4D View Pro is a new tool being developed which includes a set of features related to arrays and list presentations. It is intended to progressively replace the 4D View plug-in. For more information, please refer to the 4D Web site. To assign an object array to a list box column, you just need to set the object array name in either the Property list ("Variable Name" field), or using the LISTBOX INSERT COLUMN command, like with any array-based column. In the Property list, you can select Object as a "Variable Type" for the column: Standard properties related to coordinates, size, and style are available for object columns. You can define them using the Property list, or by programming the style, font color, background color and visibility for each row of an object-type list box column. These types of columns can also be hidden. However, the Data Source theme is not available for object-type list box columns. In fact, the contents of each column cell are based on attributes found in the corresponding element of the object array. Each array element can define:
To define these properties, you need to set the appropriate attributes in the object (available attributes are listed below). For example, you can write "Hello World!" in an object column using this simple code: ARRAY OBJECT(obColumn;0) //column array Note: Display format and entry filters cannot be set for an object column. They automatically depend on the value type. When a list box column is associated with an object array, the way a cell is displayed, entered, or edited, is based on the valueType attribute of the array element. Supported valueType values are:
4D uses default widgets with regards to the "valueType" value (i.e., a "text" is displayed as a text input widget, a "boolean" as a check box), but alternate displays are also available through options (e.g., a real can also be represented as a drop-down menu). The following table shows the default display as well as alternatives for each type of value:
You set the cell display and options using specific attributes in each object (see below). You cannot set display formats or entry filters for columns of object-type list boxes. They are automatically defined according to the value type. These are listed in the following table:
Each element of the object array is an object that can contain one or more attributes that will define the cell contents and data display (see example above). The only mandatory attribute is "valueType" and its supported values are "text", "real", "integer", "boolean", "color", and "event". The following table lists all the attributes supported in list box object arrays, depending on the "valueType" value (any other attributes are ignored). Display formats are detailed and examples are provided below.
Cell values are stored in the "value" attribute. This attribute is used for input as well as output. It can also be used to define default values when using lists (see below). Example: ARRAY OBJECT(obColumn;0) //column array Note: Null values are supported and result in an empty cell. When the "valueType" is "real" or "integer", the object also accepts min and max attributes with appropriate values (values must be of the same type as the valueType). These attributes can be used to control the range of input values. When a cell is validated (when it loses the focus), if the input value is lower than the min value or greater than the max value, then it is rejected. In this case, the previous value is maintained and a tip displays an explanation. Example: C_OBJECT($ob3) The behavior attribute provides variations to the regular representation of values. In the current version of 4D, a single variation is proposed:
Example: C_OBJECT($ob3) When a "choiceList" or a "requiredList" attribute is present inside the object, the text input is replaced by a drop-down list or a combo box, depending of the attribute:
In both cases, a "value" attribute can be used to preselect a value in the widget. Note: The widget values are defined through an array. If you want to assign an existing 4D list to the widget, you need to use the "requiredListReference", "requiredListName", "choiceListReference", or "choiceListName" attributes. Examples:
The "requiredListName" and "requiredListReference" attributes allow you to use, in a list box cell, a list defined in 4D either in Design mode (in the Lists editor of the Tool box) or by programming (using the New list command). The cell will then be displayed as a drop-down list. This means that the user can only select one of the values provided in the list. Use "requiredListName" or "requiredListReference" depending on the origin of the list: if the list comes from the Tool box, you pass a name; otherwise, if the list has been defined by programming, you pass a reference. In both cases, a "value" attribute can be used to preselect a value in the widget. Note: If you want to define these values through a simple array, you need to use the "requiredList" attribute. In this case, the "saveAs" attribute will define whether the selected item must be saved as a "value" or as a "reference".
For more information about the "save as" option, please refer to the Save as Value or Reference section in the Design Reference manual. Note: If the list contains text items representing real values, the decimal separator must be a period ("."), regardless of the local settings, e.g.: "17.6" "1234.456". Examples:
The "choiceListName" and "choiceListReference" attributes allow you to use, in a list box cell, a list defined in 4D either in Design mode (in the Tool box) or by programming (using the New list command). The cell is then displayed as a combo box, which means that the user can select or type a value. Use "choiceListName" or "choiceListReference" depending on the origin of the list: if the list comes from the Tool box, you pass a name; otherwise, if the list has been defined by programming, you pass a reference. In both cases, a "value" attribute can be used to preselect a value in the widget. Note: If you want to define these values through a simple array, you need to use the "choiceList" attribute. The "saveAs" attribute cannot be used in this case because selected items are automatically saved as a "value" (cf. for more information). Note: If the list contains text items representing real values, the decimal separator must be a period ("."), regardless of the local settings, e.g.: "17.6" "1234.456". Example: You want to display a combo box based on a "colors" list defined in the Tool box (containing the values "blue", "yellow", and "green") and display "green" by default: C_OBJECT($ob) You can use specific attributes to add units associated with cell values (e.g.: "10 cm", "20 pixels", etc.). To define the unit list, you can use one of the following attributes:
Regardless of the way the unit list is defined, it can be associated with the following attribute:
The current unit is displayed as a button that cycles through the "unitList", "unitsListReference" or "unitsListName" values each time it is clicked (e.g., "pixels" -> "rows" -> "cm" -> "pixels" -> etc.) Example: We want to set up a numeric input followed by two possible units: "rows" or "pixels". The current value is "2" + "lines". We use values defined directly in the object ("unitsList" attribute): ARRAY TEXT($_units;0) If you want to add an ellipsis button [...] to a cell, you just need to pass the "alternateButton" with the True value in the object. The button will be displayed in the cell automatically. When this button is clicked by a user, an On Alternate Click event will be generated, and you will be able to handle it however you want (see the "Event management" section below for more information). Example: C_OBJECT($ob1) The "color" valueType allows you to display either a color or a text.
The "event" valueType displays a simple button that generates an On Clicked event when clicked. No data or value can be passed or returned. Optionally, you can pass a "label" attribute. Example: C_OBJECT($ob) Several events can be handled while using an object list box array:
Compatibility note (4D v15): On Alternative Click is the new name of the On Arrow Click event that was available in previous versions of 4D. This event has been renamed since its scope has been extended.
|
PROPERTIES
Product: 4D
HISTORY
Created: 4D v15 ARTICLE USAGE
4D Language Reference ( 4D v16) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||