KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Calling Project Methods from 4D Transformation tags
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: February 11, 2016

The most commonly used ways to calling Project Methods from 4D Transformation Tags is to use the tags 4DSCRIPT and 4DEVAL. What is not commonly known is that 4DSCRIPT and 4DEVAL aren't the only tags that can be used to call a project method.

Examine the Syntax for 4DTEXT, 4DHTML, 4DIF, 4DELSEIF and 4DLOOP...

<!--#4DTEXT VarName--> or <!--#4DTEXT 4DExpression-->
<!--#4DHTML VarName--> or <!--#4DHTML 4DExpression-->
<!--#4DIF expression-->
<!--#4DELSEIF expressionN-->
<!--#4DLOOP condition-->

Within the scope of "4DExpression," "expression" and "condition," 4D project methods are tools that can be used with 4D Tags listed above. Probably the least understood is how to use a project method with with the tags 4DTEXT and 4DHTML.

Take for example the project method WeekdayName shown below and the example of how to call it using the 4DTEXT tag below it. What is requred, but not so obvious, is for 4DTEXT and 4DHTM to use a project method successfully is that the project method returns TEXT in $0.

If (True)
    If (False)
       Begin SQL
       /*
          Name: WeekdayName
          Path: WeekdayName

          Purpose: Return the name of a week day

          $0 - TEXT - Name of weekday
          $1 - LONGINT - Number of weekday
       */
       End SQL
    End if
    C_TEXT($MethodName_T)
    $MethodName_T:=Current method name
    //===================== Declare Variables ==================================
    //method_parameters_declarations
    C_TEXT($0)
    C_LONGINT($1)
    //--------------------------------------------------------------------------
    //local_variable_declarations
    C_LONGINT($Ndx;$Params_L)
   
End if
//====================== Initialize and Setup ================================

$Params_L:=Count parameters
$Ndx:=$1

//======================== Method Actions ==================================

Case of
    :($Ndx=1)
       $0:="Sunday"
    :($Ndx=2)
       $0:="Monday"
    :($Ndx=3)
       $0:="Tuesday"
    :($Ndx=4)
       $0:="Wednesday"
    :($Ndx=5)
       $0:="Thursday"
    :($Ndx=6)
       $0:="Friday"
    :($Ndx=7)
       $0:="Saturday"
    Else
       $0:=""
End case