Dephil packages)

Source: Internet
Author: User

After the application program is compiled, you can use two methods to deploy it (deploying means to distribute the application to the user ). Applications can be distributed to the public or to users in a company. Regardless of the method used, you need to know which options are available. Basically, there are two options: static links or dynamic links using packages. These options are discussed below so that programmers can make the appropriate choices to expand their applications. The following describes the options.

What is a package ?)

Before discussing the options, define the package.

A package is a piece of compiled code that resides in a file with the BPL extension.

This explanation may be hard to understand. Let's explain it further. To remove the external packaging, the package is essentially a DLL with the BPL extension (this may be a bit too much, but it is quite appropriate here ). There are two types of packages in Delphi: The runtime package and the design package. The following describes the two types of packages to help you understand how the packages work.

1. runtime packages)

The running package contains the code that the application needs to run. Although Delphi provides many different packages, the main package is vcl70.bpl, which contains all the basic VCL code. To use a package in an application, you need to mount the vcl70.bpl package and call the routine as needed. If the application is a database application, you also need to load vcldb70.bpl and call the routine as needed. In addition to the two packages mentioned here, there are other Delphi packages.

Except for the VCL package, other packages may be used by applications. This happens when a third-party component or any self-compiled component is used. You must check the documentation of third-party components to find out which packages the application needs to run. Next we will first introduce the design stage package, and then look back at the application that uses the package.

2. design packages)

Most delphi components contain a runtime package and a design phase package. The runtime package contains all the code to be run by the component. The design stage package contains the code to be run by the component on the form during design, including the Attribute Editor and component editor.

The design stage package has a requires list to notify Delphi of the packages to run. The code in the runtime package is always used for the design phase package, and one or more codes in the VCL package may also be required. A package can contain code of multiple components. The runtime package is the same as the design stage package. There is no need for a component to correspond to a separate package.

Because the design phase package only contains the Code required to display components at design, it is usually much smaller than the corresponding runtime phase package. Delphi only uses the design stage package during design, and the application does not use the design stage package.

Static linking versus Dynamic Linking)

As mentioned above, I have some basic knowledge about the package. Next I will learn about static links and dynamic links.

1. Static linking)

When an application uses a VCL static link, it no longer needs to use a package. All the code to be run by the application is directly linked to the executable file of the application. It is an independent program, no support files (packages or DLLs) are required ).

Note

There are exceptions to any rules. Static link applications do not require any two prerequisites supported by DLLs:

  1. Assume that the application is not a database application. Borland database engine (BDE) is required for running Delphi Database applications. BDE is a collection of DLLs. Therefore, this application uses static links and DLLs.
  2. It is assumed that the application does not use any ActiveX control. In fact, ActiveX control is a form of DLL. Therefore, when an application uses ActiveX control, it is no longer an independent application.

Delphi provides the link option for you to select. Static links are selected by default. Compared with Dynamic Links, static links have two main advantages:

  1. Programmers do not need to worry about Attachment File Installation. The application contains all the code to run and does not need the support of runtime libraries.
  2. Applications with static links are generally smaller than those with packages. This is also required when talking about the advantages and disadvantages of dynamic links.

Static links have an important defect, but they are only exposed to applications using many user-defined DLLs. This defect is that the VCL and RTL code are repeated in each module (the main application itself) and in each DLL, which means there is no need to repeat the code.

For example, assume that each module requires at least KB of VCL basic code and RTL code, and assume that a master application requires 10 DLLs (Dynamic Link Library) that supports it ). This means that when only KB of code is used, KB of code is used (11 modules x KB ). Applications and DLLs are both static links and cannot share VCL and RTL code between them.

2. Dynamic Link)

Dynamic Link refers to the library code that an application uses to dynamically load in the running stage. For Delphi applications, this means that any required package is loaded at the running stage. The required package will certainly include one or more VCL packages, and may need third-party packages.

Note

The application package is automatically loaded without coding. Delphi is responsible for program packaging. You do not need to make any changes to the Code when selecting dynamic links based on static links. Instead, you only need to change the way the application is distributed. This will be discussed soon.

Dynamic Links have one major advantage over static links: multiple modules can share code. Do you still remember the preceding example of "One application and 10 DLLs that support it? With Dynamic Links, the application and all its DLLs can share all the code from the VCL package. Each module can be reduced by at least kb because all the basic code is included in the runtime DLLs. This advantage is even more obvious when large software products contain multiple applications or many DLLs.

Dynamic Links also have two problems. The first problem is that the packages and DLLs that need to be transmitted together with the application may be very large, and a major VCL package, vcl70.bpl, requires 1.3 MB. In addition to the basic VCL package, the application may also need to use other packages, which means that the application must be at least 1.3mb of DLLs for running. The second problem is that dynamic links are more elusive and troublesome. This problem can be attributed to "version problems ". For example. Assume that two versions of Delphi are available, and delphi7.02 is used to create an application and select a dynamic link. Therefore, the VCL package and RTL dll must be transmitted, after the customer installs the application on his machine, everything works normally. At the same time, you can use Delphi4.0 to create an application and use dynamic links. The customer purchased the application and installed it. This installer is made in the home and is not so formal. It will overwrite the package and DLLs installed in the original application. Because the version of the package created with Delphi4.0 is lower than that of the other, the two are incompatible, and the application suddenly exits. Are you sure you want to see the problem?

In reality, commercial software companies such as Inprise solve this problem in this way: for different versions of a software, different file names are used to name its package and DLLs, and embed the version information into the package and DLLs (a good installer will automatically check the version number and only install the packages with a version later than the existing package version in the system ). Borland's package won't go wrong.

If the components used come from an irresponsible company, problems may occur. With the rapid development of the Internet, components have a wide range of sources. In many cases, it is impossible to predict what will happen, so be especially careful when purchasing cheap components or using free components.

3. Which one is better? (So which is better ?)

You may ask: Should static or dynamic links be used? The answer to this question depends on the type of the compiled application. Generally, static links should be used for compiling small-or medium-sized applications; Dynamic Links should be used for compiling large-scale applications or applications that use many DLLs.

A simple example may make the problem more intuitive. Previously we created the scratchpad program and used static links. After the program is compiled, it is about 427kb. If dynamic links are used, the size of the EXE file can be reduced to around 22kb, But the package of 1.3mb must be transmitted. In this case, dynamic links are not a good choice.

Use the runtime package (using runtime packages in your applications) in the application)

If you choose to use dynamic links, you only need to modify one of the settings in the project options. Follow these steps:

(1) select 【Project | options] Menu item. The "project options" dialog box is displayed;

(2) Click the packages page in the "Project Options" dialog box and select"Build with runtime package"Option;

(3) Click OK to close the "Project Options" dialog box;

(4) rebuilt the program;

This is all to do. Remember: Use Dynamic Links without any modifications to the code.

Deploying applications (using packages)

To distribute applications that use dynamic links, you must know which packages are used by the application. If you follow the steps in the previous step, you must know that vcl70.bpl is required, and Other VCL packages may be required, depending on the components used in the application.

To copy the packages used in the application, you must run such as tdump., then enter the following command in the command line:

tdump scratchPad.exe

Tdump immediately displays information on a scrolling screen. You can press the pause key to pause the display. Of course, scrolling may be too fast. You can direct the output of tdump to a text file so that you can view the text file. For example:

tdump scratchPad.exe > dump.txt

You can open the dump.txt file in code editorto view the content.

In the file generated by tdump, You can see content similar to the following:

Section:             Import  ImportLookUpTblRVA:00000000  Time Stamp:        00000000  Forwarder Chain:   00000000 (index of first forwarder reference)Imports from rtl70.bpl                  __fastcall System::initialization()                  __fastcall System::Finalization()                  __fastcall System::RegisterModule(System::TLibModule *)                  System::__linkproc__ __fastcall LStrAsg(void *, const void *)                  System::__linkproc__ __fastcall LStrArrayClr(void *, int)                  System::__linkproc__ __fastcall LStrClr(void *)                  System::__linkproc__ __fastcall Halt0()                  System::__linkproc__ __fastcall StartExe(System::PackageInfoTable *, System::TLibModule *)                  System::__linkproc__ __fastcall HandleFinally()                  __fastcall System::TObject::Dispatch(void *)                  __fastcall System::TObject::FreeInstance()                  __fastcall System::TObject::NewInstance(System::TMetaClass *)Imports from kernel32.dll                  GetModuleHandleAImports from vcl70.bpl                  __fastcall Forms::initialization()                  __fastcall Forms::Finalization()                  __fastcall Forms::TApplication::MessageBox(const char *, const char *, int)                  __fastcall Forms::TApplication::Run()                  __fastcall Forms::TApplication::CreateForm(System::TMetaClass *, void *)                  __fastcall Forms::TApplication::Initialize()                  __fastcall Forms::TApplication::SetTitle(const System::AnsiString)                  __stdcall Forms::TCustomForm::QueryInterface(const _GUID&, void *)                  __fastcall Forms::TCustomForm::UpdateActions()                  __fastcall Forms::TCustomForm::ShowModal()                  __fastcall Forms::TCustomForm::SetFocus()                  __fastcall Forms::TCustomForm::CloseQuery()

Find all files with the. BPL extension and record their file names. The file name under the record is the packages that must be distributed with the application.

Note

Having a good installer can save a lot of time and save a lot of trouble. The InstallShield express package is included in Delphi7 Professional Edition and Enterprise Edition, and the wise install package is also good. A good installer can indicate the packages required by the application and automatically include them. We do not recommend that you write your own installer in any environment, because there are too many issues to consider when writing the installer, and it is easy to cause problems due to weeks of consideration.

In most cases, you do not need to use the runtime package in the application, but sometimes it is not necessary to use the package.

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.