4D v13.4Developing components |
||
|
4D v13.4
Developing components
Developing components
Since a component comes in the form of a 4D database, developing a component is similar to developing a functionality in a database. There are nevertheless certain restrictions and specific rules related to the nature of components. A component can call on most of the objects of 4D: project methods, project forms, menu bars, choice lists, pictures from the library, and so on. Only the following objects cannot be used by a component:
It is not necessary to remove these elements if they exist in the matrix databases. When an “unusable” object is present, it is simply ignored once the component is installed. Note: Users and groups as well as any access rights that may have been set in the matrix database are ignored in the host database. Only project methods that are “shared” by the component are visible and can be selected in the host database in Design mode. On the other hand, project methods that are “shared” by the host database can be called by the component. For more information about this, refer to Sharing of project methods. On forms that are "published" by the component are visible and can be integrated as subforms into forms of the host database. For more information about this, refer to Sharing of forms. Other component objects (non-published project forms, choice lists, menus and so on) can be used by the component but will not be accessible as structure objects from the host database. Note that certain objects are partitioned and others are shared between the host database and the component(s). For more information about this, refer to Shared and unshared objects. A component can use the plug-ins installed in the 4D application or in the host database. It is not possible to install plug-ins in the component folder. The database methods and generic parameters of matrix databases (Web folder, Preferences, and so on) are never taken into account. The following commands are not compatible for use within a component because they modify the structure file — which is open in read-only. Their execution in a component will generate the error -10511, “The CommandName command cannot be called from a component”: ON EVENT CALL Notes:
A component cannot use the tables and fields defined in the 4D structure of the matrix database. However, you can create and use external databases, and then use their tables and fields according to your needs. You can create and manage external databases using SQL. An external database is a 4D database that is independent from the main 4D database, but that you can work with from the main 4D database. Using an external database means temporarily designating this database as the current database, in other words, as the target database for the SQL queries executed by 4D. You create external databases using the SQL CREATE DATABASE command. For more information about external databases, refer to About external databases. The following code is included in a component and performs three basic actions with an external database:
Creating the external database: <>MyDatabase:=Get 4D folder+"\MyDB" // (Windows) stores the data in an authorized directory Writing in the external database: $Ptr_1:=$2 // retrieves data from the host database through pointers Reading from an external database: $Ptr_1:=$2 // accesses data of the host database through pointers Components can use resources (“conventional” Mac OS resources or XLIFF type files). In conformity with the resource management principle (see Database Architecture), the resource files of components must be placed in a Resources folder, located next to the .4db or .4dc file of the component. If the component is of the .4dbase architecture (recommended architecture), the Resources folder must be placed inside this folder. Automatic mechanisms are operational: the XLIFF files found in the Resources folder of a component will be loaded by this component. A component will also automatically use the “conventional” Mac OS resources located in the .rsr file next to the .4db or .4dc file. “Conventional” resource files located in the Resources folder must be explicitly loaded into the component using the commands of the “Resources” theme. In a host database containing one or more components, each component as well as the host databases has its own “resources string.” Resources are partitioned between the different databases: it is not possible to access the resources of component A from component B or the host database (see Shared and unshared objects). A specific mechanism has been implemented in order to allow developers to add on-line help to their components. The principle is the same as that provided for 4D databases (see Appendix A: Assigning a custom help file) :
|
PROPERTIES
Product: 4D |