Managing Precompiled Packages
DataFlex supports precompilation of source files. When a project uses one of these precompiled packages, it will compile more quickly since part of the project has already been compiled.
We recommend that you create a precompiled package for each workspace that can be used in that workspace’s projects. If different projects need to have different precompiled files, then you can create a precompiled package for each project in the workspace.
Once you have set up a precompiled file, your projects will compile more quickly. The Studio will automatically ensure precompiled packages are kept up to date whenever they are changed.
Precompiled Package Considerations
- Only the first package that is used in your project can be precompiled. Only comments and whitespace can precede the precompiled package’s Use statement. This will place some restrictions on what can go inside a precompiled file. For example, you might not be able to place certain declarations near the top of your source code.
- The first line of code in your precompiled package can be a reference to another precompiled package. This can be used to ensure the precompiled package will also compile more quickly when needed.
- DataFlex provides precompiled versions of the most common classes you will use in a Windows or a Web Application. These packages are named
DFAllEnt.pkgandAllWebAppClasses.pkg, respectively. These are good candidates for the first Use statement in your local precompiled package. - You can create multiple layers of precompiled packages. For example, one precompiled package can use another, which in turn can use another. You might have a different precompiled package for each project in your workspace, then one precompiled package that contains common code for every project in your workspace. Each project precompile would use the workspace precompile. It is recommended to keep the number of levels of nested precompiled packages to a minimum.
- It is recommended that you do not create precompiled packages for library workspaces. Precompiling library packages might be useful if a workspace only uses a single library, only uses that single precompiled package, and it uses the file first. As more libraries are used in a workspace, these conditions become less likely. In addition, it is possible that a library precompile, which must be compiled within the library's workspace, may not represent the true state of the workspace that uses the library (e.g., pathing may be different causing different files to be found). Precompiling within a library is a limiting technique. Automatic precompiling within a workspace is more accurate and easier to use.
- When deciding what code to place inside a precompiled package, you should select code that is not likely to change very often. When a project is compiled, if the code in the precompiled package has not changed, then the project will use the precompiled package as is and compile quickly. If the code in the precompiled package has changed, then the Studio will automatically precompile the package before compiling the project. In these cases, you have not gained any advantage in compile speed.
Creating a Precompiled Package
Follow these steps to create a precompiled package for a project in the currently opened workspace:
- Select “New” > “Other” from the File menu to activate the Create New Dialog.
- Select “Empty Source File” and enter a name for the precompiled package. Select OK to create the package (e.g.,
MyPrecompile.pkg). - Add code to the package file. If you will use this package in a Windows Application, then it is recommended that the first line of code should be
Use DFAllEnt.pkg. This will ensure that your package will precompile quickly by using the system precompiled Windows classes. For Web Applications, useAllWebAppClasses.pkg. - Next, add use statements for your library classes and for local workspace classes that do not change often.
- Your precompiled package should look something like this:
Use DFAllEnt.pkg // system classes for windows applications
Use MyControlsLibrary.pkg // library classes I am using
Use MyBaseWorkspaceClasses.pkg // Workspace classes that don't change often
- Manually precompile your new package. You can do this by choosing the “Precompile Package” option from the Project menu. Once the file has been precompiled the first time, you should never need to manually precompile this file again. The Studio will understand that it should automatically maintain this precompiled file.
- Change the first line of code in your project to use the new precompiled package.
Automatic Precompilation
The compiler will detect any changes to a precompiled file or to packages used in a precompiled file when you compile a project. The Studio responds by automatically precompiling the package to bring it up to date, then continuing the compilation of your project.
This automation will work for each nested level of precompiled package that you have created in your workspace.