Tech Tip: Utility Method to Check if a Method Name Exists
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: June 17, 2015
Below is a method to check if a method exists in the database by name.
//---------------------------------------------------------------- // Method: UtilDoesMethodExist // // Description: Checks if the passed method name exists in the DB // // Parameters: // $1 - Method name to check if it exists // // $0: // Returns True if method exists // Returns Fales if method does not exist or if incorrectly called //---------------------------------------------------------------- C_TEXT($1;$methodName_t) C_BOOLEAN($0;$exist_b) ARRAY TEXT($methodNames_at) If (Count parameters=1) $methodName_t:=$1 METHOD GET NAMES($methodNames_at;$methodName_t) $exist_b:=(Size of array($methodNames_at)>0) Else $exist_b:=False End if $0:=$exist_b |
Below is an example of using the method, in a sample database with the methods listed in the following image:
Running the following code:
C_BOOLEAN($test1;$test2;$test3) $test1:=UtilDoesMethodExist ("Method3") $test2:=UtilDoesMethodExist ("Method5") $test3:=UtilDoesMethodExist () |
Will result in:
$test1 = True
$test2 = False
$test3 = False
Commented by Kirk Brooks on November 19, 2019 at 10:32 AM
Keep in mind this method checks if the method exists in the database. It does not recognize methods in components.