To continue with this content, please log in with your DataFlex Account or create a new account.
Cancel DataFlex Account
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Creating Data Dictionary Objects
Cancel

Getting to know the Data Dictionaries

Lesson 1 - What are Data Dictionaries?

Data Dictionaries in DataFlex are a layer between your application UI logic and your data, as is shown in this picture. They work for both Windows and Web applications. You could roughly say that the UI is for data entry, the Data Dictionaries are for data validation and control, and the database is for data storage.

A diagram of a computer language  Description automatically generated with medium confidence

So, the Data Dictionaries is the place where you define and manage your application business rules, such as for find, update and delete operations, which are then expressed and applied throughout your application. 

This has the following advantages:

  1. First, it lets your application interact more effectively with your database – Data Dictionaries provide your application with a wealth of information about your database that is not part of your physical database. So, it extends your database.
  2. Second, it protects your data – Data Dictionaries can make sure that only valid data is added to your database.
  3. Third, it synchronizes global database commands, such as find, relate and delete, to maintain database integrity.
  4. Fourth, it centralizes application logic – All of the information and rules about a Table is stored in a single place. So if you need to make a change, you make a change in that single place and all parts of your application acquire the change.
  5. Fifth, Data Dictionaries are database independent. Suppose you have an application that should work on different database systems, let’s say MySQL and DB2. That is entirely possible, and the same business rules of the data dictionaries work on both.
  6. And finally, Data Dictionaries are UI independent. This also means that the same Data Dictionaries can be used for creating a Web UI or a Windows UI.

So what are they in practice?

Data Dictionaries are defined as classes. You will create a Data Dictionary class for each table in your database. These classes will be used while you are building your application and when you run your application. When in the Studio you create a component, such as a view, a web page or a report, that uses a database table, you also create a so-called Data Dictionary Object, or DDO, in that component, based on the Data Dictionary class of that table. In other words, each DDOis an instance of a Data Dictionary subclass, specialized for a particular table. We’ll dive into DDO’s in lesson 2.What kind of logic would you put in a Data Dictionary? For example:

  • Do not allow a parent recordto be deleted if it has related child records. This prevents a user easily removing all or a major part of the records in the system.
  • When a new record is being created automatically assign a unique id.
  • Important validations on save and delete. For example values that needs to be in a certain range.
  • And much more.

Data Dictionaries can be very simple but also very complex. Maintenance of Data Dictionary classes is done the Studio. Data Dictionary classes are – like any other class – plain source code but can be modeled in the Studio, as we’ll see in a moment. The source code for a Data Dictionary class is stored in the DDSrc folder of the workspace.

Video example 

As an example, here is the WebOrderMobile example application, which can be installed along with the DataFlex installation. Double clicking on cCustomerDataDictionary shows a lot of settings and so-called data entry options, which we will dive into in lesson 3 and further. 

In the properties panel we can see all kinds of properties and events for this Data Dictionary class. 

There are four tab pages, called Columns, Validation Objects, Structures and Problems. 

But the Data Dictionary class is actually DataFlex code, and this whole thing is a kind of visualization of that code, a modeler. This is similar to for example a view component that can either be seen in the graphical designer or, by pressing ‘F7’, to see its code in the code editor.

So if I now press ‘F7’, it shows me the code of the Data Dictionary class. Here is the class definition. 

Don’t get overwhelmed by all the code, we’ll get into that later. But it also shows that it is highly customizable and flexible. You could just type some extra code here.

It is possible to create multiple Data Dictionary classes with varying business rules for any given table, or even multiple levels of classes that inherit from the top class down. Note the little check mark in the Data Dictionary icon. It means that this Data Dictionary is the Default Data Dictionary for this table. The Studio's modelers and wizards will always use the default Data Dictionary for any table when creating new components such as views and dialogs. By the way, it is hardly ever needed to create multiple Data Dictionary classes for a table.

Where are DDs used?

Data Dictionaries are not only used in your application; the Studio and its wizards will also use them for a number of things:

  1. To determine what tables should be opened and how they should be connected.
  2. To determine what kinds of controls should be used for a particular column (e.g., form, checkbox).
  3. To determine what labels and context help text should be used for your controls.
  4. To determine when lookup lists should be used, how it should be used, and how it will look.

Working with DDs

Working with Data Dictionaries in your application consists of three steps:

  1. Create data dictionary subclasses for each table in your database and then code database rules in these classes. This is done by setting properties and creating functions and procedures. By placing these rules in a single place, these subclasses, you will not have to repeat those rules in every component that accesses the table. We’ll go into these properties and settings in lesson 3 and higher.
  2. Create Data Dictionary Object structures inside of views, web objects and other components. A DDO structure is a group of Data Dictionary objects that are connected to provide synchronized access to related tables. We’ll look into this in lesson 2.
  3. Create objects - that is, data entry objects - or create methods (functions / procedures) inside your view, web object or other component that communicates with your DDOs. This allows you to view, create, edit or delete your data.

The rules you can specify in a Data Dictionary class will for example:

  • Define the table’s structure.
  • Specify how it connects to other tables.
  • Define what field properties and validations apply.
  • Define what rules should be applied during saves, deletes and updates.
  • Define other helper information such as label names and help text.

When running the application, all data changes go through your Data Dictionary Objects. Before data is changed in your database, the Data Dictionaries validate the data using the rules, both simple and complex, that you have built in your Data Dictionary classes.

In the next lesson we’ll go into how to apply Data Dictionaries into your application by creating Data Dictionary Objects.