DELPHI 5 Developer Guide
21.4 package
Delphi 3 introduces the Package concept, so that part of the application can be put into a separate module, so that other applications can share. The package is similar to a dynamic link library (DLL), but its usage is different. Package is mainly used to collect components and place them in an independent and shareable module (A Borland Packages Library or. BPL file. During application development, a package is similar to a dynamic link library. It is also dynamically linked to the application at runtime, rather than links during the compilation link. Because the code is stored in the. B p l file, the. EXE or. DLL file becomes very small. The difference between a package and d l is that it is dedicated to Delphi VCL. Applications written in other languages cannot use the D e l p h I package (except C ++ Builder ). The reason for using the package is that using d l has some defects. In earlier versions of Delphi, VCL always adds at least 150 KB to KB of code to each executable file. In this way, even if the application is divided into several DLL, each DLL and application contains the redundant code. Especially if a suite is developed, the problem becomes more obvious. The introduction of the package solves these problems.
21.4.1 why is package used?
There are several reasons for using the package. Three of them are discussed below.
1. Reduce code
The main reason for using the package is to reduce the size of the application and DLL. Delphi always divides v c l into several logical groups, that is, packages. In fact, many packages already exist during compilation.
2. Make applications easier to distribute
You will find that the full, demo, and update versions of many applications can be distributed over the Internet. Suppose that if you have installed a certain version of a program, you are allowed to download only the fragments of the program, not the whole application. How good is that! By splitting an application into several packages, you only need to update the areas to be updated. However, pay attention to version consistency issues.
3. inclusion components
Another important reason for using packages is to distribute third-party components. If you are a component vendor, you must understand how to create a package. The reason is that components, attribute editors, wizards, and experts are usually packaged for distribution.
21.4.2 when is package not used?
Generally, do not use runtime packages unless you are sure that other applications use runtime packages. Otherwise, it is better to compile the package directly into the application than to make the package take up space. Why? If a package is used, the length of the application will be reduced from kb to 30 kb, which seems to save a lot of space. However, the score is also sent, and there may be another vc150. DCP package. The package size is 2 MB. In this way, it seems that it is not as much space as you think. We recommend that you consider using packages if several applications need to share code. Note that this is only applicable to runtime packages. If you are a component writer, you must provide a design period package containing components.
21.4.3 package type
There are four types of packages:
• Runtime package. The runtime package contains the Code required by the application during running. If an application uses a runtime package, the package must be distributed with the application. Without this package, the application cannot run.
• Design period package. The design phase package includes components, attributes, component editors, experts, and so on. These are all required by the IDE during design. This type of package only applies to the Delph I environment and is not distributed along with the application.
• Runtime and design period packages. This package is both a runtime package and a design phase package. This package generally does not contain anything dedicated during the design period, such as attributes, component editors, and experts. Using this package can simplify application development and distribution. However, if such a package contains something specific during the design period, the application will contain something redundant. We recommend that you avoid including design-specific items when creating such a package.
• It is neither a runtime package nor a design phase package. This type of package is rarely used. It is generally used by other packages and is not directly used by applications or in the design environment.