4D provides libraries to help you develop applications. One of these libraries is standard and contains preconfigured form objects and widgets, while other libraries are custom. The standard library is “read-only” and its behavior doesn’t change when developing project databases (with the exception of minor, cosmetic interface differences). You also have the ability to create your own custom libraries to save your own form objects or group of objects. In this case, a few changes have been made to make them even more powerful. The following is everything you need to know about these changes:
A new library is a new project
When you develop an application as a project, any custom libraries you create will also be projects … regular, standalone projects. Libraries are no longer in “.4dlibrary” folders, even though they behave exactly the same as libraries previously created in binary databases.
two points to consider
can any project be opened as a library?
Before answering this question, you need to understand what a library is. Essentially, a library is a set of forms inside a database structure. Each item in the library’s dialog corresponds to a project form inside this database structure. Therefore, each time you add or remove an object to or from a library, 4D creates or removes a project form from its database structure.
Knowing this, the answer to the above question is “yes”, but there’s two small caveats to be aware of:
- If you open a regular project as a library, only project forms will appear in the library dialog; All other forms (i.e. table forms) will be ignored. The library dialog will display as many items as there are project forms in your database, no more, no less.
- On these project forms, only objects belonging to the first form page will be reachable. All other objects (i.e., belonging to page zero or pages other than the first one) will also be ignored.
What about my previous (binary) libraries?
Legacy 4D libraries can not be opened when the current database is a project, they must be converted first. This is really a quick and easy operation, so let’s take a look at how:
- Windows users can skip the first step, otherwise (i.e. you work on macOS) you must rename your library by removing its “.4dlibrary extension” (or replace the “.” by an “_” for example). This renaming action will transform the package into a regular folder that you can open. (You can also use the “show package content” contextual menu, but getting rid of the extension is a better way to go. 🙂 )
- Once this is done, you’ll see a .4IL file and (probably) a Resources folder. Just change the file extension from .4IL to .4DB.
Guess what? The file is now a regular 4D file that can be opened by 4D! Open the file and create a .4DD file when prompted.
The next step is conversion, or to be more precise, “Export”. You may have used this option previously if you’ve already converted legacy (binary) databases into projects.
- Open the “File” menu and select “Structure to project” in the Export submenu (File > Export > Structure to project). Once done, you’ll be prompted to open the project. Take a look to see what happens behind the scenes!
- Quit and the job is completed. Your library is converted!
Now that your binary library has been converted to a project, it can be opened as a library by any other 4D Project!
In the example below, the “Background” form belongs to a database under development. Open the “Alpha” library to get the set of buttons you have saved there, then drag (or copy/paste) to the “Background” form!
As you can see, 4D libraries are easier than ever to use. They’re an easy way to share items with coworkers or to save buttons, icons, widgets, etc. Take a look at the documentation to learn even more!