Calling Function Methods using Expressions
DataFlex supports two distinct ways to call Function Methods. The first syntax is to use a Get statement, while the second syntax is to call the method within an expression.
Syntax for Calling Function Methods
Get Statement Syntax
The syntax of the Get statement for calling a Function method is:
Get {method-name} [of {object-id}] {param1 … paramN} To {variable-id}
Where:
{method-name}is the name of the Function method that is being executed.{object-id}is a handle to the object whose method is being executed.{variable-id}is the name of a variable that is assigned the value returned by the Function method.
This syntax is fully discussed in the section on Calling Function Methods.
Expression Syntax
The syntax for calling a Function method using an expression is:
({method-name}({object-id}[, param1 …, paramN]))
Notice that the {object-id} is a compulsory part of the expression syntax for calling a Function method. The function's parameters follow the {object-id}, and each parameter is delimited by a single comma.
If the object being called is the same as the object sending the message, the keyword Self must be used as the {object-id}.
Example of Expression Syntax
Below is an example of using expression syntax to call a function, followed by the equivalent Get statement:
Move (Calc_Sales_Tax(Self, nAmount)) To nSalesTax // self is required
Get Calc_Sales_Tax nAmount To nSalesTax // self is implied
Calc_Sales_Tax of Self nAmount To nSalesTax // optional use of self
If the object being called is a different object than the object sending the message, the object must be named. Refer to the section on Other Object Access Methods for more information.
Move (Calc_Sales_Tax(oSalesDD, nAmount)) To nSalesTax
or,
Move oSalesDD to hoSalesDD
Move (Calc_Sales_Tax(hoSalesDD, nAmount)) To nSalesTax
or,
Get Calc_Sales_Tax of oSalesDD nAmount To nSalesTax
Using Object Functions in Complex Expressions
Object functions may also be used as part of complex expressions:
Move (Calc_Sales_Tax(oSalesDD, nAmount) / 100) To iSalesTax
or,
Get Calc_Sales_Tax of oSalesDD nAmount To nSalesTax
Move (nSalesTax / 100) to iSalesTax
Passing Multiple Parameters
The following example passes two parameters to a function:
Move (Field_Option(oCustomerDD, iField, iOption)) To bOption
Get Field_Option of oCustomerDD iField iOption To bOption
The Field_Option example shown above requires that the field number of the field you are querying is stored in the variable iField. Retrieving this field number requires some special code. The Get statement version of this example can be rewritten in the following way:
Get Field_Option of oCustomerDD FIELD Customer.Name iOption To bOption
where Customer.Name is the field identifier of the field that you are querying. This is a much more convenient way to pass parameters to Function methods that require field numbers. Unfortunately, the expression syntax version cannot pass field identifiers in this way. Refer to Declaring Procedure Set Methods for more information.