We know that sometimes you want to change the properties of multiple methods without having to open the property dialog for each method.
For example, you want to set all methods to “Can be run in preemptive mode” status, then compile your database. So with compilation errors, you get an overview of the methods to modify to be preemptive.
Using the METHOD GET NAMES command to retrieve the list of methods from your database, and then using the METHOD SET ATTRIBUTES command to modify the attributes, lets you modify them all at the same time!
Here is an example setting all project methods to preemptive mode:
ARRAY TEXT($arrName;0)
C_OBJECT($attributes)
// Retrieve all methods in structure
METHOD GET NAMES($arrName)
// Create object with the "preemptive" attribute set to "capable"
OB SET($attributes;"preemptive";"capable")
// Change the "preemptive" attribute value for all methods
For ($i;1;Size of array($arrName)
METHOD SET ATTRIBUTES($arrName{$i};$attributes)
End for
Use a collection to manipulate properties
4D now has a new type, collections, and many ready-to-use methods to handle collections.
So how do you use this new type? You insert method names and properties into a collection to search, modify, or simply display it in a list box of collection type.
Here is an example to store all method properties in a collection:
C_OBJECT($attributes)
C_COLLECTION(colMethod)
ARRAY TEXT($arrName;0)
colMethod:=New collection()
// Retrieve all methods in structure
METHOD GET NAMES($arrName)
For ($i;1;Size of array($arrName)
$attributes:=New object()
// Retrieve the attributes for each method
METHOD GET ATTRIBUTES($arrName{$i};$attributes)
// Add item in the collection
colMethod.push(New object("name";$arrName{$i};"attributes";$attributes))
End for
After editing the attributes, you can save the result with a simple loop on the collection:
C_OBJECT($item;$tmp)
// Loop for each item in the collection
For each ($item;colMethod)
// Save attributes
$tmp:=$item.attributes
METHOD SET ATTRIBUTES($item.name;$tmp)
End for each