Skip to content

Use

See Also: #INCLUDE

Purpose

To incorporate separate source files into DataFlex programs at compile time either as precompiled modules or as source code.

Syntax

use ["{path}"] {SourceFileName}[{.ext}]

Where:

  • {Path} is optional.
  • {Path} can be relative or absolute, but is typically relative to the main source path (e.g., AppSrc in a typical workspace).
  • If {path} contains spaces, the entire path and filename should be enclosed in quotes.
  • {.ext} is not required if the extension is .pkg, but it is encouraged.

What It Does

The use command searches for the file {SourceFileName.ext} at the time the program is compiled. If the specified file is found and has not already been included in the program, its contents are loaded and compiled as though they were part of the program. If the file is not found, an error is reported.

A use package is only included once in a program. If the same package is used more than once, it is included the first time, and subsequent use commands are ignored.

use FinFuncs.pkg

In this example, the file FinFuncs.pkg is incorporated into the compiling program if it has not already been included with a previous use command.

Subfolder Paths

Any source path may contain subfolder paths, which provides an effective and recommended mechanism for organizing your files.

All subdirectories defined within a source path are considered to be part of the workspace. Files in these workspace subdirectories must be referenced relative to their location in the main source path, which is most often your AppSrc folder.

For example, assume you have the file AccountsEntry.vw located in the following folder structure:

C:\DataFlex Projects
└── Order Entry
    ├── AppSrc
    │   ├── AccountsPayable
    │   │   └── Views
    │   │       └── AccountsEntry.vw
    │   └── Reports
    │       └── AccountsReceivable
    │           └── Views
    └── DDSrc

This file is accessed relative to the main source path, AppSrc, and is therefore referenced as follows:

use AccountsPayable\Views\AccountsEntry.vw

The file will be located relative to your main source paths. In the above example, it will find the file under the AppSrc path (C:\DataFlex Projects\Order Entry\AppSrc\AccountsPayable\Views\AccountsEntry.vw).

Note that your use statement must include the entire relative path. The following statement would not find the same file:

use AccountsEntry.vw  // this will not find the same file

In this case, the file would have to be located directly under a main source path (e.g., ...\AppSrc\AccountsEntry.vw).

Subdirectories will be used most often under the AppSrc path. However, subdirectories may be located under any of the main workspace source paths (e.g., AppSrc, DDSrc) and all library source paths. All paths will be searched until the file is found, with the path defined as AppSrc always searched first.

Precompiled Code

Precompiled portions of source code may be incorporated into your programs by pre-compiling the package file and placing a use {SourceFileName.pkg} statement as the first (non-comment) line of your program. This saves time in the compilation of the overall program. If the precompiled file is missing, or some other non-comment statement precedes the use command, the {SourceFileName.pkg} file will be recompiled as usual. This technique is typically used to include your pre-compiled "all entry" package – the package that includes all packages normally used by your application.

The default name for the DataFlex standard "all entry" package for Windows projects is DFAllent.pkg. The default name for the DataFlex standard "all entry" package for web projects is AllWebAppClasses.pkg.

// top of program
use DfAllent.pkg   // this can (and should) be precompiled
use FinFuncs.pkg   // this cannot be precompiled

Notes

  • Used files may themselves use other files, without limit. If through this or some other occurrence, the same {SourceFileName.ext} file is used more than once, the file will be included only the first time. This is a key difference between use and the #INCLUDE compiler directive.