Skip to content

Load_Def

See Also: Outputting DEF Files, Make_File, Structure_Copy

Purpose

Loads table-definition information from a sequential (.DEF) file into memory.

.DEF files are designed to work with the embedded database. We recommend using the native tools of the database you are working with to maintain table definitions.

Syntax

Load_Def {def-file} Onto {structure-handle}

Where {def-file} is the name of the sequential file to load, and {structure-handle} is a handle to an existing or new table structure.

What It Does

The Load_Def command loads a table definition from {def-file} into the table structure identified by {structure-handle}. The Load_Def command may only be used within a Structure_Start ... Structure_End block. Load_Def may be used on restructure operations for both new and existing tables.

No structure operations (other than Structure_Start) should be performed on {structure-handle} prior to executing Load_Def, because the Load_Def command overwrites most of the table definition. Any structural changes prior to executing Load_Def are lost.

The Load_Def command is similar to Structure_Copy. They both copy an existing table structure onto a new one. Load_Def uses a definition (.DEF) file as the source, while Structure_Copy uses an open database table as the source.

When you use Load_Def with (.DEF) files, you need to be aware of some special rules that allow you to easily create new table definitions:

  1. Fields are matched by number.
  2. To delete a field, remove the line from the .DEF file. All fields beneath the deleted field will be shifted up by one position. New field numbers will be assigned automatically.
  3. To add a field, place the field in the position you want it to have, and give it a number of zero (0). All fields beneath this field will be shifted down one position. New field numbers will be assigned automatically.
  4. To modify a field, change the requested data (name, type, etc.) for the field number you want to change. If you modify the type, the data will be converted appropriately.

Example

Handle hTable
String sTableName
Boolean bDefFileExists

// Check for Wines.Def
File_Exist "Wines.Def" bDefFileExists
If (bDefFileExists) Begin
    // The name of the table will be Test1
    Move "Test1" To sTableName
    // Using a table handle of 0 with Structure_Start indicates
    // that we are creating a new table.
    Move 0 to hTable
    Structure_Start hTable "DATAFLEX"

    // Load the definition file of an existing table onto the table
    // being created. Use the Wines table definition as a template.
    Load_Def "Wines.Def" Onto hTable
    Set_Attribute DF_FILE_PHYSICAL_NAME of hTable to sTableName
    Structure_End hTable DF_STRUCTEND_OPT_NONE

    // Now we create the filelist entry for our new table.
    // This command gets the next available number in filelist.cfg
    Get_Attribute DF_FILE_NEXT_EMPTY to hTable

    // These commands set the table names associated with the
    // filelist.cfg entry for the new table (Test1)
    Set_attribute DF_FILE_LOGICAL_NAME of hTable to sTableName
    Set_attribute DF_FILE_DISPLAY_NAME of hTable to sTableName
    Set_attribute DF_FILE_ROOT_NAME of hTable to sTableName
    Send Stop_Box "Success" "Exit Program."
End

This example creates a new table, Test1, using the definition file of an existing table, Wines. You may use the Wines.Def file in the Wines sample to try this program. A filelist entry is also created for the new table.

Notes

  • Load_Def will not modify your file list.
  • Load_Def will not end the restructure operation—to complete the operation, you must execute a Structure_End command.
  • If {structure-handle} is a handle to an existing table, it will not change the folder name of the table.