The design idea of Delphi package and its relation with PAS, BPL, DCU, DLL, Oxc.

Source: Internet
Author: User

DCP, what is the BPL? You create a package in Delphi and then save it and see.

BPL and DLLs are similar. It's just that BPL is Borland himself out of something!!! The call is similar to calling a DLL, Loadpackage () ... Dcp:delphi an editing package ; A file containing information about code symbols that are compiled into a package.

This file does not contain compiled code, which is actually stored in the DCU or BPL file, and the Bpl:borland program package Libraries : A file containing VCL components used in the design of the Delphi environment or when the application is running (this file is in Delphi3 . DPL extension)

======================================

DCP = Delphi Compiled package, which is produced by the package compile with BPL, records the class, procedure, function, variable, and const in the package. And so on the names and relative addresses.
If a control package a refers to control package B, when control package a compiles, a control package B.DCP is required, and if the control package B has been modified to change the exposed interface, control package a must be recompiled after the control package B is compiled to reference the new B.DCP. Otherwise, an error occurs when the control package A executes to the content that references the auto-control package B.
====================================================, the introduction of various documents in Delphi, and their relationship.

The Oxc:activex control. will be installed in a component package dpk, and the PAS, DCU, DCR three files will be created in imports.

DLL: Dynamic link library file, its exports exports can be written in the project file, can also be written inside the unit, no difference.

DPK: A component package file, which is a collection of multiple components (PAS).

BPL: Package file, is actually DLL file, just add some features on the basis of the DLL: such as checking duplicate unit. It is required by the Delphi IDE integrated development environment and is a file generated by the DPK compilation. Where the Run-time type is used for running EXE, Design-time type for use by Delphi. Different versions are not the same format. It can write exports like a DLL.

DCU: Compiled files, which are generated by the PAS compilation (quite obj files), the connector can use DCU to connect the code to the target output file. Each Delphi version produces a different DCU format.

Second, the design idea of the package

A package is a special dynamic link library that is shared by the application in the Delphi IDE environment. The package allows us to use a multi-level application to share part of our program as a separate module for other applications. Since the compiled DPL is a special DLL, you can write the export statement in a unit that belongs to a dpk.

1, static links and dynamic links.

Static Link is when a Delphi project is compiled, all the code required by the project will be directly linked to your program execution files. The result is that the execution file will contain all the cells that the program needs to use (units), and you might say that the code is a bit verbose because, by default, the uses clause of a form unit lists at least 5 basic units (for example, Windows, Messages, Sysutils, etc.), however, Delphi can intelligently automatically link the code that is actually used in the unit to the project code, thus minimizing the size of the execution file. Using static linking, our application is a relatively independent program that does not require any additional supporting files or dynamic link libraries (for the time being, the BDE and ActiveX artifacts are not considered). The default use of Delphi is static link mode.

Dynamic linking is the application that runs with a standard dynamic-link library (DLL). The dynamic linking method does not need to set up the code directly into each application, to provide multi-threaded library function support for multiple applications, only the packages that are needed during the run of the program will be loaded, and it is worth mentioning that the package that the program needs to invoke dynamically is automatically loaded, so you do not need to write the code to load the package specifically. The Setup method is: Select "Options", "Project", "Packages", select the "Build with Runtime Packages" check box, the program code will be automatically linked to the dynamic run package, Instead of connecting the reference unit to your project execution file statically chained. If you have "build with Runtime Packages", then at compile time, then it does not need what dcu/pas.

For example:

Open the Delphi default project (only a blank form), F9 it compiles an executable file that generates approximately 365 KB (DELPHI7). Then open "Project", "Options", "Packages", the "Build with Runtime Packages" selected and then compile, exe file size is only about a KB.

When we compile a Delphi application, we do not select "Build with Runtime Packages" by default, and the compiler will write the code needed to run the program directly into your EXE file, so the resulting program is a relatively unique Not require any ancillary supporting files (such as the Dynamic runtime file DLL), it also knows why the application that Delphi produces is so large. To establish the smallest possible Delphi program, one way to give full play to the role of Borland package libraries, referred to as BPL.

2, the classification of the package:

It can be broadly divided into run-time packages (Run-time Packages) and design-time packages (Design-time Packages):

Run-time Packages: support for VCL and library functions when running a program, similar to the standard dynamic-link library.

Design Period Package: Used to install the control in the Delphi IDE environment and to create a special property editor for the control. Design-time packages allow the inclusion of controls, properties, and control editors, and so on, in an IDE environment, such packages are required for programming, and are only used by Delphi, and are not distributed with developed applications.

3. The necessity and benefits of separating the package and the design period of the running period:

The design-time code is not executed at run time, and the compiler does not know that all the code is linked in, so a separate design prevents code bloat. A run-time package, a design-time package, makes the size of the application smaller and avoids all of the associated cells being linked to the executing program (DELPHI5 and previous versions), which expands the code.

Another benefit is to reduce the occurrence of compilation errors, since the Delphi6 version, the VCL structure of the DELPHI5 and the previous version has been adjusted, Borland with designintf replaced Dsgnintf, and the property editor is also placed in the De Signeditors, Designmenus, designwindows and other design documents. In particular, Designeditors used a different IDE file called proxies. The proxies is compiled into the DESIGNIDE.BPL file. DESIGNIDE.BPL is no longer a file that can be distributed, we can only use it in the development environment, needless to say, "File not found" occurs when compiling the application. At this time, we will run the package and design phase of the package separately, the design period package to join the DESIGNIDE.DCP file, compile the package file separately, you can guarantee the correct, compile through!

Package Packages It is similar to DLLs, but is only common in Delphi and Cbuilder environments. Good use of the package, you can make the program module clear, to maximize the code reuse, so that the volume of the program as far as possible, and can be used in both locales interoperability.

4, in order to make the code structure optimization, the design period package should include:

1>, all registration statements (preferably in a separate unit);

2>, all the attribute editors;

3>, all component editors;

4>, the package that will require Designide support (DESIGNIDE.DCP file, write in requires: Designide).

Note: The component editor is a component that pops up a shortcut menu, such as a table, on a component. Its production is similar, is inherited from under the Tcomponenteditor.

5, in order to optimize the code structure, run-time package should include:

1>, the component itself.

2>, the form that the component may invoke at run time (property editor).

Note: The package is designed differently depending on the version, and the editor version of Delphi 6.0 is the Ver140,delphi 5.0 editor version is VER130, if we want to adapt to different versions need to use {$IFDEF VER140} ... {$ELSE} ... {$ENDIF}; control in uses domain, this is a little attention.

Iii. timely use of parcel BPL and DLLs

It is generally considered that joining the Dynamic Runtime library in the Windows operating system is one of the most useful and efficient applications. Because in Windows systems, many applications run at the same time may cause memory problems, and many programs perform similar operational tasks, but each is controlled and completed by different code. The purpose of the dynamic runtime is to put the code in your execution program into a DLL in a system-shared environment. Perhaps the most intuitive example of a dynamic link library is the Windows operating system itself and its own API.

dynamic-link libraries are typically used to assemble procedures (procedure) and functions (function) for program invocation. Of course, while we are writing the dynamic link library, we can also put a Delphi form into a DLL (for example, a AboutBox form), and we can also store the resources required by the program in the DLL.

In contrast to DLLs, the concept of a package is unique to Delphi development, and applications written in other languages cannot refer to a package created by Delphi. The package is a dynamic link library that can be used by Delphi's application, and it also gives the Delphi programmer more support for library functions.

Usually we build dynamic link libraries (DLLs) in Delphi to store the processes and functions that applications need to use in different environments, and the package can contain not only code units (unit), Artifacts and forms (form), but also classes in Delphi. (such as classes, so that we can refer to the Object Wizard encoding in it (object Oriented code). In the package, we can save the full Universal Delphi component, while the Dynamic Runtime Library (DLL) is powerless.
In addition, DLLs and BPL play an equally important role in reducing program code, mainly because the file size of the program is reduced directly after using the package or dynamic link library technology. Of course, the DLL or BPL that the execution program needs to load can also be very large. However, if you want to distribute multiple applications that share the same package, you can save a lot of things. When the user party system already exists the program to run the necessary parts of the file (such as: Standard Delphi BPL), only need to download the program's minimum execution files. If program engineering is distributed and carried out mainly through the Internet, there is obviously a great improvement in efficiency.
The application of the package also saves system memory because the result of a dynamic link is that only one VCL is read into memory for use by all Delphi applications that use the run-time package.

Iv. basic steps for building a package:

1. Start Delphi and select "File", "close all" to close the default project.

2. Select "File", "New". , the New Items dialog box pops up, and then "new", "package", and the parcel editor appears by double-clicking. The package editor consists of 2 folders: Contains and requires.

3. Click "Add" to add a unit file (widget or a simple code unit file).

(Note: You are adding a pas source file instead of the compiled DCU file.) When you add a unit file, the name of the unit in the package is displayed in the Contains folder of the package editor. Open the requires folder, the expanded list represents the DCP files for packages that are required for the package, and the most basic of the package file is the need to reference the VCL.DCP file containing most of the standard visual controls. You can also see the required

Additional packages to be added)

4. Then click Options and in the "Usage Options" group in the "Description" panel you will need to select the type of package.

(Design-time package, run-time package, or both.) If you choose Runtime only (run-time package only), the user of the other package will have no

Installation of components into the IDE environment)

5. Save the Package project file (DPK) using "File", "Save", and then save the package file, such as AboutDP70.

6. In the Package editor, click the Compile button to compile the package. If you do not make an error, a package file (BPL file) will be created after the bundle is compiled.

7, completed, BPL file has been successfully established, waiting for the use of.

8. There is an install button in the Parcel editor, which is used to install the current package into a design period package. If the package is

Run-time only (run-time package only), the Install button will not be available.

With respect to these documents, in addition to the DPK file and those unit source files, Delphi also uses the dynamic link version of the package to generate a BPL file and a DCP file containing the identity information contained in the package, which is the compilation file of the unit file included in the package (DC U) is a collection of identity information.

The release package needs to include: DCP (contains header information for the package and individual unit files) and. bpl files, all cell files of the. dcu file.

The design idea of Delphi package and its relation with PAS, BPL, DCU, DLL, Oxc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.