A Seamless Way to Manage Parameters

In the declaration of a function or method, you explicitly define its parameters. Then, when calling that function or method, you can pass fewer parameters to it if some are optional. Or, if you used the declaration with ${n}, the number of passed parameters is variable. In this case, you use the Count Parameters command with a loop over the arguments. This code works flawlessly. Still, it’s a little bit heavy.

You asked us for a lighter way to handle parameters, and we listened. Starting with 4D v19 R5, we provide you with a new command, Copy parameters, allowing you to write a seamless, more elegant, and easier-to-read code. 

See the new command in action.

New command

The new command, Copy parameters, returns a collection of the parameters passed to a function or a method. If you pass the “startFrom” parameter to the Copy parameters command, it returns a collection that contains the element from the “startFrom” index.


 Manipulate the parameters as a collection. For example, concatenate a string with the parameters to create an unordered HTML list:

// Class
Function list() -> $html : Text  
 var $value : Collection
 $value:=Copy parameters 
 return $html

// Method
// $htmlList: <ul><li>Alpha</li><li>Bravo</li><li>Charlie</li></ul>


Call a different function depending on the first parameter and pass the other parameters to this method:

Function selectTask($task : Text)  
 Case of
  : ($task="Task1")
  This.task1(Copy parameters(2))
  : ($task="Task2")
  This.task2(Copy parameters(2))  
 End case


Or, call another function on another object with apply() and pass the parameters:

Function doSomething($param : Text; $extraParameters : Variant)
 This.delegate.doSomething.apply(This.delegate; Copy parameters)


You can read the documentation for more information. Do not hesitate to share your ideas and examples on the forum.

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.