
With the upcoming conzept 16 version 5.7.05, you will be able to dynamically create list and column objects—that is, at runtime.
This allows you to build variable list objects using procedures as needed, eliminating the need to prepare them with hidden columns.
Read this article to learn how this works and what you need to keep in mind.
The dynamic creation of UI objects is performed using the function WinCreate(), which has been part of the feature set since version 5.7.01, as has the function WinAdd(), which is called to add one object to another.
The list items—which can be created dynamically—are
-
- DataList (
_WinTypeDataList), - DataListPopup (
_WinTypeDataListPopup), - RecList (
_WinTypeRecList), - RecListPopup (
_WinTypeRecListPopup),
- DataList (
- StoList (
_WinTypeStoList), - StoListPopup (
_WinTypeStoListPopup) and - RecView (
_WinTypeRecView)
as well as the column objects
- Column (
_WinTypeListColumn, for Data, Rec, and StoList objects) and - GroupColumn (
_WinTypeGroupColumn, for RecView objects).
Example
// Create a DataList object named “dlsMyDataList”
tWinDataList # WinCreate(_WinTypeDataList, 'dlsMyDataList');
// Set position (x: 8, y: 8) and dimensions (120 x 80, W x H):
tWinDataList->wpArea # RectMake(8, 8, 128, 88);
// Add a DataList object to a Frame object
aWinFrame->WinAdd(tWinDataList);
You have now created a DataList object and added it to a Frame object, though it does not yet have any columns. These are created in the same way.
Example
// Create a column named “clmMyColumn” with the label “No.”
tWinColumn # WinCreate(_WinTypeListColumn, 'clmMyColumn', 'Nr.');
// Add a column to the list
tWinDataList->WinAdd(tWinColumn);
This creates a Column object—that is, a column—and adds it to the DataList object—the list. The list object itself can also be a static one, which you can expand with additional columns in this way. Dynamically created Column objects have, among other things, the following properties:
wpVisible = true,wpClmType = _TypeAlpha,wpDbFieldName = '',wpClmWidth = 70undwpClmOrder = _MaxInt.
You can customize the properties as desired after they have been created. The wpClmType property is relevant only for DataList and DataListPopup objects, while the wpDbFieldName property is relevant only for RecList and RecListPopup objects.
Note: Starting with this version, the wpClmType property can also be modified for static columns, provided the DataList object does not contain any rows.
The wpClmOrder property determines the display position of the column. Columns with a small value are positioned on the left, while columns with a large value are positioned on the right. At the maximum value (_MaxInt), they are therefore always positioned on the far right. After positioning, the value of the property is set to the actual display position.
Example
// Show the column in the third position
tWinColumn->wpClmOrder # 3;
// Add a column to the list
tWinDataList->WinAdd(tWinColumn);
The index position of the column—which, for example, must be specified in the WinLstCellSet() function—is determined by the insertion order, which can be controlled using the WinAdd() function. Specifically, a subsequent column can be specified, in front of which the column to be inserted is placed. If no subsequent column is specified, the column is inserted after the last existing column.
You can only add or remove a column before the last position as long as the list is empty—that is, as long as a DataList object contains no rows or a RecList object has no table or key assigned to it. You can add or remove a column at the last position at any time.
Example
// Determine the first column
tWinColumnRef # tWinDataList->WinInfo(_WinFirst);
// Determine the third column
tWinColumnRef # tWinColumnRef->WinInfo(_WinNext, 2);
// Insert a column at the third position (index = 3)
tWinDataList->WinAdd(tWinColumn, 0, tWinColumnRef);
...
// Add row
tLine # tWinDataList->WinLstDatLineAdd(...);
// Set third cell
tWinDataList->WinLstCellSet(..., 3, tLine);
Dynamic generation offers you many new, flexible, and resource-efficient ways to customize lists to suit your specific needs.
We look forward to seeing how you put this into practice =).