4D v16.3

Creating and using custom object libraries

Home

 
4D v16.3
Creating and using custom object libraries

Creating and using custom object libraries  


 

 

You can create and use object libraries in 4D. An object library is an external file created by 4D where you can store all types of objects (buttons, texts, pictures, hierarchical lists, etc). You can then use these objects in different forms. Objects are stored with all their properties, including their object methods. Libraries are put together and used by simple drag-and-drop or copy-paste operations. They are a little like a permanent clipboard. 

Using libraries, you can build form object backgrounds grouped by graphic families, by behavior, etc. Since these libraries are stored as an external file, their use with different databases is quite easy. 

Finally, you can combine object libraries with user forms in order to supply objects that can be used to customize databases. These principles are described in User forms.

To create an object library, select the New>Object Library... command from the 4D File menu or tool bar.

A standard save file dialog box appears, which allows you to choose the name and the location of the object library.

Once you validate the dialog box, 4D creates a new object library on your disk and displays its window (empty by default).

You can create as many libraries as desired per database. A library created and built under Mac OS can be used under Windows and vice-versa.

Objects are placed in an object library using drag-and-drop or a cut-copy-paste operation. They can come from either a form or another object library (including the preconfigured library, see Using the preconfigured library). No link is kept with the original object: if the original is modified, the copied object is not affected.

Note: In order to be able to drag and drop objects from forms to object libraries, you must select the “Start drag and drop” option in the 4D Preferences (see the Forms Page).

Basic operations such as adding, deleting or renaming are available in the context menu or the options menu of the window:

You can place individual objects or sets of objects in an object library. Each object or set is grouped into a single item:

An object library can contain up to 32,000 items.

Objects are copied with all their properties, both graphic and functional. These properties are kept in full when the item is copied into a form or another library.

Each new item is named “Object,” followed by a random number, for example Object2012. This item can be renamed as desired. To do that, you can:

  • Double-click the item to rename
  • Right-click the item to rename, then choose the Rename command in the context menu. A dialog box appears allowing you to rename the item:

    More than one item can have the same name.

Using copy-paste or drag-and-drop with certain library objects also causes their dependent objects to be copied. For example, copying a button will cause the object method that may be attached to be copied as well. These dependent objects cannot be copied or dragged and dropped directly.

The following is a list of dependent objects that will be pasted into the library at the same time as the main object that uses them (when applicable):

  • Lists
  • Stylesheets
  • Formats/Filters
  • Pictures
  • Help Tips (linked to a field)
  • STR# resources
  • Object methods

For STR# resources, the entire STR# is copied and not just the string associated with the object.

To open an existing object library, select the Open>Object Library... command in the 4D File menu or tool bar.

A standard open file dialog box appears, which allows you to select the object library to open. A given object library can only be opened by one database at a time. However, several different libraries can be opened in the same database. The extension of libraries is “.4il.”

Object libraries can be accessed from the 4D Design environment and, if the developer allows it, in the User form editor (see User forms) in Application mode. All library items are visible in the Design environment. However, only items without an associated object method are visible in the User form editor.

Items with at least one associated object method are displayed with a shield (the same one displayed on objects with an object method in a form, see Using shields) and their name appears in blue. This allows easily distinguishing items that are visible for the developer in the Design environment from those that are visible for the user in the Application environment.

In order for all client machines to be able to access an object library, the library file must be placed in the Resources folder of the database (see Description of 4D files). This folder in particular lets you share custom elements between the server and the client machines (pictures, XLIFF files, etc.). For more information, refer to Managing the Resources folder in the 4D Server Reference Manual. 
You can view and manage the contents of the Resources folder via the Resources explorer.



See also 

Using the preconfigured library

 
PROPERTIES 

Product: 4D
Theme: Building forms

 
HISTORY 

 
ARTICLE USAGE

4D Design Reference ( 4D v16)
4D Design Reference ( 4D v16.1)
4D Design Reference ( 4D v16.3)