Change the properties of several methods at once by code

Automatically translated from English

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)

// Retrieve all methods in structure

// 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:

ARRAY TEXT($arrName;0)
colMethod:=New collection()

// Retrieve all methods in structure

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:

// Loop for each item in the collection
For each ($item;colMethod)
 // Save attributes
End for each

Demo: Change method properties by code

Vanessa Talbot

• Product Owner •

Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.