Note | This command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available |
Produce a new database file with the field definitions taken from the contents of a structure-extended file.
CREATE <xcTargetFile> FROM <xcSourceFile> [NEW] [ALIAS <xcAlias>] [VIA <cDriver>]
<xcTargetFile> | The name of the target database file to create, including an optional drive, directory, and extension. After the file is created, it remains open in the mode specified by the SetExclusive() flag for the work area. |
If <xcTargetFile> does not exist, it is created. If it exists, this command attempts to open the file in exclusive mode and, if successful, the file is overwritten without warning or error. If access is denied because, for example, another process is using the file, NetErr() is set to TRUE. |
<xcSourceFile> | The name of a structure-extended file to use as the structure definition for the new database file, including an optional drive, directory, and extension. |
If <xcSourceFile> does not exist, a runtime error is raised. If it exists, this command attempts to open the file in shared mode and, if successful, it proceeds. If access is denied because, for example, another process has exclusive use of the file, NetErr() is set to TRUE. |
See SetDefault() and SetPath() for file searching and creation rules. The default extension for database files is determined by the RDD. |
To qualify as a structure-extended file, the structure of the database file must be the same as the structure generated by COPY STRUCTURE EXTENDED, which you can refer to for more details. |
Note: For data dictionary applications, you can have additional fields within the structure-extended file to describe the extended field attributes. You can, for example, have fields to describe such field attributes as a description, key flag, label, color, picture, and a validation expression for the VALID clause. CREATE FROM creates the new database file from the required fields only, ignoring all other fields in the extended structure. Moreover, it is not sensitive to the order of the required fields. |
NEW | Selects the next unoccupied work area before opening <xcTargetFile>. If this clause is not specified, the current work area is used. |
ALIAS <xcAlias> | An identifier name to associate with the work area when <xcTargetFile> is opened. If this clause is not specified, the alias defaults to the database file name. Duplicate alias names are not allowed within a single application. |
VIA <cDriver> | The name of the RDD that will service the work area. If not specified, the default RDD as determined by RDDSetDefault() is used. |
Character field lengths greater than 255: There are two methods for creating a character field with a length greater than 255 digits:
• Specify the field length using both the Field_Len and Field_Dec fields according to the following formulation:
• _FIELD->Field_Len := <nLength> % 256
• _FIELD->Field_Dec := Integer(<nLength> / 256)
• Modify the structure of the structure-extended file by changing the length of Field_Len to 5, then specify the actual field length.
This example is a procedure that simulates an interactive CREATE utility:
FUNCTION Start()
CreateDatabase("newfile")
FUNCTION CreateDatabase(cNewDbf)
// Create empty structure-extended file
CREATE tmpext
USE tmpext
lMore := TRUE
DO WHILE lMore
// Input new field definitions
APPEND BLANK
CLEAR
@ 5, 0 SAY "Name.....: " GET Field_Name
@ 6, 0 SAY "Type.....: " GET Field_Type
@ 7, 0 SAY "Length...: " GET Field_Len
@ 8, 0 SAY "Decimals.: " GET Field_Dec
READ
lMore := (!EMPTY(Field_Name))
ENDDO
// Remove all blank records
DELETE ALL FOR EMPTY(Field_Name)
PACK
CLOSE
// Create new database file
CREATE (cNewDbf) FROM tmpext
ERASE tmpext.dbf
The next example creates a new definition in a structure-extended file for a character field with a length of 4000 characters:
APPEND BLANK
REPLACE Field_Name WITH "Notes",;
Field_Type WITH "C",;
Field_Len WITH 4000 % 256,;
Field_Dec WITH INTEGER(4000 / 256)
XSharp.RT.DLL
COPY STRUCTURE, COPY STRUCTURE EXTENDED, CREATE, DbCopyXStruct(), DbCreate(), RDDSetDefault(), SetDefault(), SetExclusive(), SetPath()