Tech Tip: Determine the Listbox Data Source programmatically
PRODUCT: 4D | VERSION: 17R4 | PLATFORM: Mac & Win
Published On: February 8, 2019
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Here is a utility method to determine the Listbox Data Source programatically:
// ----------------------------------------------------------- // Method: DETERMINE_DATA_SRC_LISTBOX_TYPE // Description: Method will determine the data source of the // Listbox // // Parameters: // $1 (TEXT) - Listbox name // // Output: // $0 (TEXT) - arrays, currentSelection, namedSelection, // , collection, or (blank) for no type // ----------------------------------------------------------- C_TEXT($1;$lbName) C_TEXT($0;$value) C_OBJECT($formObj;$elem) C_COLLECTION($col) $lbName:=$1 $formObj:=FORM Convert to dynamic(Current form name) $col:=$formObj.pages For each ($elem;$col) If ($elem#Null) If (OB Is defined($elem.objects;$lbName)=True) If (OB Is defined($elem.objects[$lbName];"listboxType")=False) $value:="arrays" Else $value:=$elem.objects[$lbName].listboxType End if End if End if End for each $0:=$value |
Here is an example of determining an array based Listbox:

C_TEXT($type) $type:=DETERMINE_DATA_SRC_LISTBOX_TYPE ("ListBox") // arrays |
Here is an example of determining an selection based Listbox:

$type:=DETERMINE_DATA_SRC_LISTBOX_TYPE ("ListBox") // currentSelection or namedSelection |
Here is an example of determing an Collection/Entity based Listbox:

Also when looking at the first column of the Listbox that could have either a Collection or Entity (Object):

$type:=DETERMINE_DATA_SRC_LISTBOX_TYPE ("ListBox") // collection |
Commented by Vincent de Lachaux on March 11, 2019 at 2:28 AM
Since dot notation is available :
For each ($o;FORM Convert to dynamic(Current form name).pages) Until (Length($Txt_dataSource)#0)
If ($o.objects[$Txt_name]#Null)
$Txt_dataSource:=Choose($o.objects[$Txt_name].listboxType=Null;"arrays";String($o.objects[$Txt_name].listboxType))
End if
End for each