s

When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Partner Programs 4D Partner Central

FileMaker Pro to 4th Dimension Quickstart Guide

How the 4th Dimension Database Was Created

Rather than starting from scratch, we chose to create this database using one of the 4th Dimension templates. Templates are simple databases that can be used as-is, or as a starting point for a custom solution. Templates are available for contact management, invoicing, asset management, and more. There's also a bare-bones template (called 4D Shell) if one of the standard templates doesn't meet your needs.

For this project, we selected the 4D Product Sales template as our starting point, since it most closely resembled the FileMaker Pro database. We could have also developed this database starting with the 4D Shell, or from scratch.

As noted earlier, 4th Dimension has three modes: the Design environment, the User environment, and the Custom Menus environment. The 4D Templates are designed for use primarily in the Custom Menus environment. Although the database can still be used in the User environment, this mode will only be accessible to the database developer or system administrator. By limiting access to the Custom Menus environment, the developer has complete control over both the appearance and behavior of the final solution.

When the 4D Orders database is launched, it automatically opens up in the Custom Menus mode. The menu bar you see here is completely customizable by the developer (although access to the Help menu is limited).

The Use menu has been added to all of the 4D Templates to make it easier for the developer to navigate between modes. This menu should generally be removed before delivering the final database. Without this menu, it's still possible for the developer to get to the Design environment of an interpreted database. Access to the design environment can be protected from end-user access using 4D's password system or by compiling the database before delivery.

Since you have complete access to the source code of the 4D Templates, you can modify any aspect of their look or behavior. However, no major changes were made to the template for this example. We just modified the structure slightly to match the structure of the FileMaker example, then updated the forms.

It's also important to note here that everything you see in this database was done with just the 4th Dimension application. Additional functionality can also be added using plug-ins (similar to FileMaker Pro extensions), but none were needed for this example.

The Structure Editor

When you get into the Design environment you'll see the Structure window. This window shows the database structure. This gives you a quick view of the database's tables (4D's equivalent to files), fields, and the relationships between the tables.

The first thing we did was modify the structure to match the file names and field names used in the FileMaker Pro database. Here is the structure in 4th Dimension's Structure Editor:

structure editor screen shot

Tables

Note that not all of the tables seen in the Structure Editor window are fully visible to the user. For example, the History table can be accessed only through a Customer record. The user doesn't have direct access to the History table. Line items are available only through an Order record.

You'll also see a Shell table with no fields. This table exists just to hold forms, which we'll describe a little later. This table won't be used directly by the end user, so it's been marked as Invisible in the Table Properties palette. This prevents it from appearing in the Query, Order By, Import, and Export windows in the Custom Menus environment.

Fields

4th Dimension is optimized to allow faster access of Alpha fields than Text fields, so the First Name, Last Name, and other alphanumeric fields were set to Alpha, rather than Text. These fields have an "A" and the maximum string length displayed to the right of the field name. Text fields (the fields with a "T" next to the field name) are used only where we might want to store more than 80 characters, as with the Product Description field. To view the Field Properties palette, double-click on a field name in the Structure Editor.

field properties palette screen shot

There are no global or calculated fields, since these capabilities are handled differently by 4th Dimension. Variables are used instead of global fields. Functions are written instead of using calculated fields.

In the History table, the field name Event Date was used rather than Date, since Date is a 4D function name. Type is also a 4D function name, so the Type field was renamed Event Type.

It's more common to use a Long Integer field rather than an Alpha field to store record IDs, but for this database we copied the style used in the FileMaker Pro database just to show it can be done. This would make it easier to import data from the FileMaker Pro database and retain the record relations.

You might also notice that all of the 4D tables have an ID field as the first field, even if this wasn't done in the FileMaker Pro database. Since you can't move or delete a field once it has been created in 4D, it's just customary in 4D development to do this, even if the field is not initially needed.

The relations we needed for this database were already set up by the 4D Product Sales template. To view the properties of a relation, click the relationship line between two tables. Relations are created just by dragging from a field in the many table to a field in the one table.

relation properties screen shot

The system is designed so that customer records can't be deleted if they have any orders. This was done by selecting the "Cannot delete if related many" radio button in the Relation Properties dialog for the relationship between the Customers and Orders tables (double-click the relationship line between the two tables to see this dialog). By changing the selected radio button, we could also have designed the system to allow us to delete customers even if they had orders, or automatically delete any related orders when the customer record is deleted.

The Form Editor

To view a form (4D's term for a layout), display the Explorer window by selecting Explorer from the Tools menu. Then click on the second tab to display the list of forms. You'll see a list of the tables in the database. In 4D, as in FileMaker Pro, each form must be connected to a table. Click the icon to the left of the Customers table name to expand the list and display the table's forms. Double-click on the Input form to open the Form Editor window.

form editor window screen shot

In addition to the Form Editor window, two palette windows will appear. The Property List allows you to configure the properties for the form or selected object. The Tools palette allows you to add new objects to the form, or modify groups of objects.

You'll notice that you can select objects in the Orders area of the form, but you can't select other form objects. That's because most of this form's objects are on page 0, the form's master page. Objects on the master page are visible when viewing any form page. To switch to page 0, select Goto Page from the Form menu and then select 0 from the submenu. Once you're on page 0, you'll be able to work with the objects on the master page.

Remember how the FileMaker Pro database used multiple layouts and buttons to mimic the tabbed area? In 4D we just added a tab object. It automatically handles the page switching for us (although it could also be handled by code). Use the Goto Page menu item to go to page 2 to see the History form objects.

Both page 1 and 2 contain an included form (4D's version of a portal) to another table. You an double-click an included form to open it in the Form Editor.

The New, Edit, and Delete buttons next to each included form allow us to modify records from the related table. 4th Dimension includes Standard Actions you can assign to a button to handle these actions for you. However, the 4D Product Sales template uses code for these buttons to get additional functionality not offered by the automatic options.

In 4D, almost any object can contain a method (similar to a script in FileMaker Pro). 4D can run the object's method when the form is first loaded, when it's clicked or a key is pressed, etc. The black triangle in the top-left corner of an object indicates it has a method.

To view the object method of the New button, select the New button object by clicking on it once, then select Object Method from the Object menu. Or you can just Option-click (Mac) or Alt-click (Win) on the object. A new window appears with the object's method. This is the Method Editor window.

Forms can also have methods. Return to the Customers Input form and then select Form Method from the Form menu. A new Method Editor window appears with the form's method.

Besides having master pages, a 4D form can also display the contents of another form. Bring the Explorer window to the front by selecting Explorer from the Tools menu, then double-click on the Customers table's Output form.

The buttons at the top of this form aren't actually in this form. This form inherits the objects from the Shell table's Shell_Toolbar form. The Orders and Products Output forms also inherit this button palette. If we make any changes to the Shell_Toolbar form, the change is reflected automatically in each of the Output forms.

shell toolbar screen shot

The Method Editor

Besides adding methods to forms and form objects, we can also create stand-alone methods, called Project Methods. Project Methods all you to create your own commands and functions. These methods can be called from object or form methods, at startup, and from other places.

Project Methods are similar to the form and object methods we've already looked at, but each has its own unique name. To view the Project Methods in this database, open the Explorer window again by selecting Explorer from the Tools menu. Then click on the third tab. Click the icon to the left of the Project Methods label to reveal the list of Project Methods in this database.

explorer window screen shot

A project method can have any name, but since they're displayed in alphabetical order, it helps to prefix the names to group them. In the list of project methods, notice many start with "Shell_." These methods are included in the basic 4D Shell (4th Dimension developers often refer to a database designed to be used as a starting point as a "shell") template available from the 4D web site.

Since this database was based on the 4D Product Sales template (which was based on the 4D Shell template), most of the other project methods in this list were already created for us. However, we changed some of the method names to match the table names used in this example. For example, the methods that started with "Contacts_" were renamed "Customers_", and the "Invoices_" methods were renamed "Orders_." In fact, only the "Customers_LoadHistory", "Orders_FindCustomers", and "Compiler_History" project methods were added to the database (although minor code changes were made to many of the existing project methods).

Menus

The menu bar you see in this example is provided by the 4D Product Sales template. The only change we made was to rename "Contacts" to "Customers," and "Orders" to "Invoices." To view the menu bar, select Menu Bar Editor from the Tools menu.

Next: Creating Your Own 4th Dimension Solution

Previous: 4th Dimension Sample File Overview


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D, Inc. 1995-2008 | Change font size: [A] [A] [A] | Print this page | 4D RSS Feeds