KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility to determine if a DB is running in HOST or COMPONENT mode
PRODUCT: 4D | VERSION: 13.x, 14.x, 15.x | PLATFORM: Mac & Win
Published On: July 28, 2016

When developing a component it is handy to determine at startup if the application is running in HOST or COMPONENT mode. In HOST mode there may be some startup code that is desirable to run that is not in COMPONENT mode.

The utility below will return TRUE in HOST mode and FALSE in COMPONENT mode.

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

         Purpose: Am I running as a component or a host DB

         $1 - BOOLEAN - TRUE quals HOST mode, FALSE equals COMPONTENT mode
       */
       End SQL
    End if
    C_TEXT($MethodName_T)
    $MethodName_T:=Current method name
    //===================== Declare Variables ==================================
    //method_parameters_declarations
    C_BOOLEAN($0)
    //--------------------------------------------------------------------------
    //method_wide_constants_declarations
    //--------------------------------------------------------------------------
    //local_variable_declarations
    C_LONGINT($Ndx;$SOA;$RIS;$Params_L)

End if
//====================== Initialize and Setup ================================

$Params_L:=Count parameters

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

// When the command is called from a method of the host database,
// it always returns the long name of the structure file of the host database,
// regardless of whether or not the * parameter is passed.
//
// TRUE quals HOST mode, FALSE equals COMPONTENT mode
//
$0:=(Structure file(*)=Structure file)

//======================== Clean up and Exit =================================


Use example in the On Startup method...

If (UTIL_CompRunningInHostMode)
    // Run some code in HOST mode
End if