KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Dynamically inserting project method names as text for New Formula
PRODUCT: 4D | VERSION: 17R3 | PLATFORM: Mac & Win
Published On: January 18, 2019
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

When creating an object that contains a project method which can be used at a later time with the New Formula requires to be declared and tokenized as the example shown below:

C_OBJECT($f)

$f:=New formula(addMethod )
$sum:=$f.call(null;1;2) // 3

// addMethod
C_LONGINT($0;$1;$2)

$0:=$1+$2


The following utility method can dynamically create an object with a project name using text:

//---------------------------------------------------------------------------------
// Name: newObjectWithProjectName
// Description: Method will create a object with New Formula with given
// Project Method Name.
//
// Parameters:
// $1 (TEXT) - Project Method Name
// Output:
// $0 (OBJECT) - Created object from New Formula
// --------------------------------------------------------------------------------
C_TEXT($1;$methodName)
C_OBJECT($0;$a)

$methodName:=$1

EXECUTE FORMULA("$a:=New formula("+$methodName+")")

$0:=$a


Here is the same example of using the method:

C_OBJECT($f)

$f:=newObjectWithProjectName("addMethod")
$sum:=$f.call(null;1;2) // 3