KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Component Methods and Host Methods
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: February 1, 2018

Creating a built component can be useful when developing an application. In general, the component methods are made access-able to the host database which allows the host database to call methods in the component as long as the component method is correctly installed and shared with the host method.

For example, to allow the component method "Method_B" to be accessible by the host, enable the option from within the component database.



After the share property for the methods in the component database are enabled, simply build the application and move the build methods into the components folder of the host database.



New folder "component_method_Build" with "Components" created next to the component .4dbase file.



Move the newly built .4dbase file into the Components folder of the host .4dbase package (create the "Components" folder if none exists or simply copy the "Components" folder with the component .4dbase file).



The component method will then be available in the Component Methods dropdown in the Methods tab of the Explorer window.



The component method will not be able to be opened to view the code from within the host database, but the method can be used from the host simply by making a method call.



Documentation here: Component Installation and Compatibility Documentation

Although a component method does not typically have access to the host methods, for security reasons, it is possible to grant access for the component method to the host method by checking the same option on the host method that is checked within the component.

For example, if you want to allow the host method "Method_C" to be accessible by the component, enable the option from within the host database. The host method will not show up in the Component Methods dropdown in the Methods tab of the Explorer window for the component database but will be access-able by the component nonetheless.



The component will now be able to access the host method "Method_C" however the method cannot be called simply with the method name. This is because when the component method is called from the host, the context is then inside the component and thus any normal method call within the component context will be on from component.

To call the host method from within the component the 4D command EXECUTE METHOD can be used and as long as the host method has been shared the method will run.



For example if host method "Method_A" calls component method "Method_B" which needs to call the host method "Method_C", using EXECUTE METHOD will allow this to be done and then the result (output) from the host method "Method_C" can then be used within the component method "Method_B" for further manipulations.

// Method_A in host (calls Method_B in component)
Method_B

// Method_B in component (calls Method_C from host)
C_LONGINT($result)
EXECUTE METHOD("Method_C";$result;5)
ALERT("Result is: "+String($result))

// Method_C in host
C_LONGINT($1;$input;$0)
$input:=$1
$0:=$input*10