KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Loading a hierarchical list from a thread-safe execution.
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: May 20, 2024

Loading a hierarchical list programmatically cannot be done from a thread-safe method. Here is a way to get around this restriction.

Execute the following method in the On Startup or On Server Startup to load all lists into the storage.

// Method: preloadLists
var $i : Integer
var $newList_c : Collection
ARRAY TEXT($list_at; 0)
ARRAY LONGINT($list_al; 0)
LIST OF CHOICE LISTS($list_al; $list_at)
Use (Storage)
  Storage.list:=New shared object
  Use (Storage.list)
    For ($i; 1; Size of array($list_at))
      ARRAY TEXT($item_at; 0)
      LIST TO ARRAY($list_at{$i}; $item_at)
      $newList_c:=New shared collection
      Use ($newList_c)
        ARRAY TO COLLECTION($newList_c; $item_at)
      End use 
      Storage.list[$list_at{$i}]:=$newList_c
    End for 
  End use 
End use 


Use the following method to get a list based on a name in the form of a collection.
// Method: getList
#DECLARE($name_t : Text)->$list_c : Collection
If (Storage.list[$name_t]#Null)
  $list_c:=Storage.list[$name_t]
End if