Using System Files in Data Dictionaries
Visual DataFlex system files are designed to contain only one record. You can apply this attribute by setting the database file’s maximum number of records to one (1) in Database Builder. System files can be the main file or an updated file of a DDO and should be treated just like a related file.
Additionally, system files should never be cleared, and their (only) record should never be deleted. Consequently, DDOs prevent these two operations from being performed on system files. Furthermore, since a system file’s record is automatically found when the file is opened, manually finding the record is unnecessary. As a result, the only time a DDO redisplays the data for a system file is after the system file has been saved. If you wish to redisplay it, you can send the entry_display message, passing the explicit file number of the system file.
Often, system files are not assigned a DDO. System files represent the one exception to the Framework rule that states that a data-dictionary subclass should be created and used for every data file in an application. Instead, you may name the file in an add_system_file message, whose syntax is:
Send Add_System_File integer file_number [integer lock_type]
This procedure adds file_number to the data-dictionary structure. It is used for system files and other files that, although part of the locking structure, do not have their own DDOs through which to connect to the data-dictionary structure. lock_type specifies the type of locking to be used with file_number:
- DD_Lock_On_All: Lock on all saves and deletes
- DD_Lock_On_New_Save_Delete: Lock on new saves and deletes
- DD_Lock_On_Save: Lock on all saves
- DD_Lock_On_New_Save: Lock only on new saves
- DD_Lock_On_Delete: Lock only on deletes
For system files supporting unique ID serial numbers, DD_Lock_On_New_Save should be sufficient; for files supporting counters that increment and decrement, the other two modes would be required, so DD_Lock_On_All would be appropriate. System files can be detached with remove_system_file.
Send Add_System_File OrdSys.File_Number DD_Lock_On_New_Save
You may create a system-file data-dictionary subclass and object and connect this DDO to your data-dictionary structure. If you do this, you would not need to save the system file in your creating procedure; the DDO will do this for you automatically. If you do this, you should make sure that any DDO that directly uses the system file explicitly connects to the system-file DDO with an updating link.
In the following example, both Customer and Order use the system file Sysfile to supply record keys. Therefore, the DDOs for both directly provide an updating link to the system-file DDO:
Object Order_View is a dbView
Object Sysfile_DD is a Sysfile_DataDictionary
End_Object
Object Customer_DD is a Customer_DataDictionary
Set DDO_Server to (Sysfile_DD(Self))
End_Object
Object Order_dd is an Order_DataDictionary
Set DDO_Server to (Customer_DD(Self))
Set DDO_Server to (Sysfile_DD(Self))
End_Object