Tech Tip: Dynamically inserting project method names as text for New Formula
PRODUCT: 4D | VERSION: 17R3 | PLATFORM: Mac & Win
Published On: January 18, 2019
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 |